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