From 19a0cd6bfe814d076eda950e740af67de319f8b6 Mon Sep 17 00:00:00 2001 From: jsing Date: Fri, 10 Aug 2018 16:12:19 +0000 Subject: [PATCH] Use a table rather than a switch when converting strings to NIDs. This will make it easier to extend. --- .../lib/libcrypto/wycheproof/wycheproof.go | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/regress/lib/libcrypto/wycheproof/wycheproof.go b/regress/lib/libcrypto/wycheproof/wycheproof.go index ee53195f023..086d583e47c 100644 --- a/regress/lib/libcrypto/wycheproof/wycheproof.go +++ b/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) { -- 2.20.1