diff options
author | jsing <> | 2018-08-10 16:12:19 +0000 |
---|---|---|
committer | jsing <> | 2018-08-10 16:12:19 +0000 |
commit | 507af682823da29bc058fd3eb408e337950cda11 (patch) | |
tree | 509c0670e9cb551cc44257d6970c569b135421b3 /src | |
parent | 7727cc5ce3ffe6beb726ad0b743f3eff7ba1bd68 (diff) | |
download | openbsd-507af682823da29bc058fd3eb408e337950cda11.tar.gz openbsd-507af682823da29bc058fd3eb408e337950cda11.tar.bz2 openbsd-507af682823da29bc058fd3eb408e337950cda11.zip |
Use a table rather than a switch when converting strings to NIDs.
This will make it easier to extend.
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/wycheproof/wycheproof.go | 27 |
1 files changed, 13 insertions, 14 deletions
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 @@ | |||
1 | /* $OpenBSD: wycheproof.go,v 1.1 2018/07/25 18:04:09 jsing Exp $ */ | 1 | /* $OpenBSD: wycheproof.go,v 1.2 2018/08/10 16:12:19 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -75,21 +75,20 @@ type wycheproofTestVectors struct { | |||
75 | TestGroups []*wycheproofTestGroup `json:"testGroups"` | 75 | TestGroups []*wycheproofTestGroup `json:"testGroups"` |
76 | } | 76 | } |
77 | 77 | ||
78 | var nids = map[string]int{ | ||
79 | "SHA-1": C.NID_sha1, | ||
80 | "SHA-224": C.NID_sha224, | ||
81 | "SHA-256": C.NID_sha256, | ||
82 | "SHA-384": C.NID_sha384, | ||
83 | "SHA-512": C.NID_sha512, | ||
84 | } | ||
85 | |||
78 | func nidFromString(ns string) (int, error) { | 86 | func nidFromString(ns string) (int, error) { |
79 | switch ns { | 87 | nid, ok := nids[ns] |
80 | case "SHA-1": | 88 | if ok { |
81 | return C.NID_sha1, nil | 89 | return nid, nil |
82 | case "SHA-224": | ||
83 | return C.NID_sha224, nil | ||
84 | case "SHA-256": | ||
85 | return C.NID_sha256, nil | ||
86 | case "SHA-384": | ||
87 | return C.NID_sha384, nil | ||
88 | case "SHA-512": | ||
89 | return C.NID_sha512, nil | ||
90 | default: | ||
91 | return -1, fmt.Errorf("unknown NID %q", ns) | ||
92 | } | 90 | } |
91 | return -1, fmt.Errorf("unknown NID %q", ns) | ||
93 | } | 92 | } |
94 | 93 | ||
95 | func hashFromString(hs string) (hash.Hash, error) { | 94 | func hashFromString(hs string) (hash.Hash, error) { |