aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam Langley <agl@golang.org>2017-08-18 13:38:09 -0700
committerAdam Langley <agl@golang.org>2017-09-09 19:36:51 +0000
commit4933da68b5c36d0a9c2a02fe9ed2f5ce2c9c3239 (patch)
treedb2d216deb0ecad41acbe1e3db86c9991ccda0d5 /src
parent083ad28622580195a97cbe83a877c7d49b1dadfa (diff)
downloadgo-4933da68b5c36d0a9c2a02fe9ed2f5ce2c9c3239.tar.xz
crypto/x509: store names in signatureAlgorithmDetails.
There is already a table of signature algorithm details so the code should use it for the name too. This avoids mismatches. Change-Id: I0d4befbae721ec43db9f87cd93173ec12749e4c8 Reviewed-on: https://go-review.googlesource.com/57210 Run-TryBot: Adam Langley <agl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/crypto/x509/x509.go57
1 files changed, 21 insertions, 36 deletions
diff --git a/src/crypto/x509/x509.go b/src/crypto/x509/x509.go
index ab33994ad5..4324e89168 100644
--- a/src/crypto/x509/x509.go
+++ b/src/crypto/x509/x509.go
@@ -194,27 +194,11 @@ func (algo SignatureAlgorithm) isRSAPSS() bool {
}
}
-var signatureAlgoName = [...]string{
- MD2WithRSA: "MD2-RSA",
- MD5WithRSA: "MD5-RSA",
- SHA1WithRSA: "SHA1-RSA",
- SHA256WithRSA: "SHA256-RSA",
- SHA384WithRSA: "SHA384-RSA",
- SHA512WithRSA: "SHA512-RSA",
- SHA256WithRSAPSS: "SHA256-RSAPSS",
- SHA384WithRSAPSS: "SHA384-RSAPSS",
- SHA512WithRSAPSS: "SHA512-RSAPSS",
- DSAWithSHA1: "DSA-SHA1",
- DSAWithSHA256: "DSA-SHA256",
- ECDSAWithSHA1: "ECDSA-SHA1",
- ECDSAWithSHA256: "ECDSA-SHA256",
- ECDSAWithSHA384: "ECDSA-SHA384",
- ECDSAWithSHA512: "ECDSA-SHA512",
-}
-
func (algo SignatureAlgorithm) String() string {
- if 0 < algo && int(algo) < len(signatureAlgoName) {
- return signatureAlgoName[algo]
+ for _, details := range signatureAlgorithmDetails {
+ if details.algo == algo {
+ return details.name
+ }
}
return strconv.Itoa(int(algo))
}
@@ -320,26 +304,27 @@ var (
var signatureAlgorithmDetails = []struct {
algo SignatureAlgorithm
+ name string
oid asn1.ObjectIdentifier
pubKeyAlgo PublicKeyAlgorithm
hash crypto.Hash
}{
- {MD2WithRSA, oidSignatureMD2WithRSA, RSA, crypto.Hash(0) /* no value for MD2 */},
- {MD5WithRSA, oidSignatureMD5WithRSA, RSA, crypto.MD5},
- {SHA1WithRSA, oidSignatureSHA1WithRSA, RSA, crypto.SHA1},
- {SHA1WithRSA, oidISOSignatureSHA1WithRSA, RSA, crypto.SHA1},
- {SHA256WithRSA, oidSignatureSHA256WithRSA, RSA, crypto.SHA256},
- {SHA384WithRSA, oidSignatureSHA384WithRSA, RSA, crypto.SHA384},
- {SHA512WithRSA, oidSignatureSHA512WithRSA, RSA, crypto.SHA512},
- {SHA256WithRSAPSS, oidSignatureRSAPSS, RSA, crypto.SHA256},
- {SHA384WithRSAPSS, oidSignatureRSAPSS, RSA, crypto.SHA384},
- {SHA512WithRSAPSS, oidSignatureRSAPSS, RSA, crypto.SHA512},
- {DSAWithSHA1, oidSignatureDSAWithSHA1, DSA, crypto.SHA1},
- {DSAWithSHA256, oidSignatureDSAWithSHA256, DSA, crypto.SHA256},
- {ECDSAWithSHA1, oidSignatureECDSAWithSHA1, ECDSA, crypto.SHA1},
- {ECDSAWithSHA256, oidSignatureECDSAWithSHA256, ECDSA, crypto.SHA256},
- {ECDSAWithSHA384, oidSignatureECDSAWithSHA384, ECDSA, crypto.SHA384},
- {ECDSAWithSHA512, oidSignatureECDSAWithSHA512, ECDSA, crypto.SHA512},
+ {MD2WithRSA, "MD2-RSA", oidSignatureMD2WithRSA, RSA, crypto.Hash(0) /* no value for MD2 */},
+ {MD5WithRSA, "MD5-RSA", oidSignatureMD5WithRSA, RSA, crypto.MD5},
+ {SHA1WithRSA, "SHA1-RSA", oidSignatureSHA1WithRSA, RSA, crypto.SHA1},
+ {SHA1WithRSA, "SHA1-RSA", oidISOSignatureSHA1WithRSA, RSA, crypto.SHA1},
+ {SHA256WithRSA, "SHA256-RSA", oidSignatureSHA256WithRSA, RSA, crypto.SHA256},
+ {SHA384WithRSA, "SHA384-RSA", oidSignatureSHA384WithRSA, RSA, crypto.SHA384},
+ {SHA512WithRSA, "SHA512-RSA", oidSignatureSHA512WithRSA, RSA, crypto.SHA512},
+ {SHA256WithRSAPSS, "SHA256-RSAPSS", oidSignatureRSAPSS, RSA, crypto.SHA256},
+ {SHA384WithRSAPSS, "SHA384-RSAPSS", oidSignatureRSAPSS, RSA, crypto.SHA384},
+ {SHA512WithRSAPSS, "SHA512-RSAPSS", oidSignatureRSAPSS, RSA, crypto.SHA512},
+ {DSAWithSHA1, "DSA-SHA1", oidSignatureDSAWithSHA1, DSA, crypto.SHA1},
+ {DSAWithSHA256, "DSA-SHA256", oidSignatureDSAWithSHA256, DSA, crypto.SHA256},
+ {ECDSAWithSHA1, "ECDSA-SHA1", oidSignatureECDSAWithSHA1, ECDSA, crypto.SHA1},
+ {ECDSAWithSHA256, "ECDSA-SHA256", oidSignatureECDSAWithSHA256, ECDSA, crypto.SHA256},
+ {ECDSAWithSHA384, "ECDSA-SHA384", oidSignatureECDSAWithSHA384, ECDSA, crypto.SHA384},
+ {ECDSAWithSHA512, "ECDSA-SHA512", oidSignatureECDSAWithSHA512, ECDSA, crypto.SHA512},
}
// pssParameters reflects the parameters in an AlgorithmIdentifier that