From 507af682823da29bc058fd3eb408e337950cda11 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Fri, 10 Aug 2018 16:12:19 +0000 Subject: Use a table rather than a switch when converting strings to NIDs. This will make it easier to extend. --- src/regress/lib/libcrypto/wycheproof/wycheproof.go | 27 +++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/regress/lib/libcrypto/wycheproof/wycheproof.go b/src/regress/lib/libcrypto/wycheproof/wycheproof.go index ee53195f02..086d583e47 100644 --- a/src/regress/lib/libcrypto/wycheproof/wycheproof.go +++ b/src/regress/lib/libcrypto/wycheproof/wycheproof.go @@ -1,4 +1,4 @@ -/* $OpenBSD: wycheproof.go,v 1.1 2018/07/25 18:04:09 jsing Exp $ */ +/* $OpenBSD: wycheproof.go,v 1.2 2018/08/10 16:12:19 jsing Exp $ */ /* * Copyright (c) 2018 Joel Sing * @@ -75,21 +75,20 @@ type wycheproofTestVectors struct { TestGroups []*wycheproofTestGroup `json:"testGroups"` } +var nids = map[string]int{ + "SHA-1": C.NID_sha1, + "SHA-224": C.NID_sha224, + "SHA-256": C.NID_sha256, + "SHA-384": C.NID_sha384, + "SHA-512": C.NID_sha512, +} + func nidFromString(ns string) (int, error) { - switch ns { - case "SHA-1": - return C.NID_sha1, nil - case "SHA-224": - return C.NID_sha224, nil - case "SHA-256": - return C.NID_sha256, nil - case "SHA-384": - return C.NID_sha384, nil - case "SHA-512": - return C.NID_sha512, nil - default: - return -1, fmt.Errorf("unknown NID %q", ns) + nid, ok := nids[ns] + if ok { + return nid, nil } + return -1, fmt.Errorf("unknown NID %q", ns) } func hashFromString(hs string) (hash.Hash, error) { -- cgit v1.2.3-55-g6feb