typeAndHashFromSignatureScheme returns the corresponding signature type and crypto.Hash for a given TLS SignatureScheme.
(signatureAlgorithm SignatureScheme)
| 97 | // typeAndHashFromSignatureScheme returns the corresponding signature type and |
| 98 | // crypto.Hash for a given TLS SignatureScheme. |
| 99 | func typeAndHashFromSignatureScheme(signatureAlgorithm SignatureScheme) (sigType uint8, hash crypto.Hash, err error) { |
| 100 | switch signatureAlgorithm { |
| 101 | case PKCS1WithSHA1, PKCS1WithSHA256, PKCS1WithSHA384, PKCS1WithSHA512: |
| 102 | sigType = signaturePKCS1v15 |
| 103 | case PSSWithSHA256, PSSWithSHA384, PSSWithSHA512: |
| 104 | sigType = signatureRSAPSS |
| 105 | case ECDSAWithSHA1, ECDSAWithP256AndSHA256, ECDSAWithP384AndSHA384, ECDSAWithP521AndSHA512: |
| 106 | sigType = signatureECDSA |
| 107 | case Ed25519: |
| 108 | sigType = signatureEd25519 |
| 109 | default: |
| 110 | return 0, 0, fmt.Errorf("unsupported signature algorithm: %v", signatureAlgorithm) |
| 111 | } |
| 112 | switch signatureAlgorithm { |
| 113 | case PKCS1WithSHA1, ECDSAWithSHA1: |
| 114 | hash = crypto.SHA1 |
| 115 | case PKCS1WithSHA256, PSSWithSHA256, ECDSAWithP256AndSHA256: |
| 116 | hash = crypto.SHA256 |
| 117 | case PKCS1WithSHA384, PSSWithSHA384, ECDSAWithP384AndSHA384: |
| 118 | hash = crypto.SHA384 |
| 119 | case PKCS1WithSHA512, PSSWithSHA512, ECDSAWithP521AndSHA512: |
| 120 | hash = crypto.SHA512 |
| 121 | case Ed25519: |
| 122 | hash = directSigning |
| 123 | default: |
| 124 | return 0, 0, fmt.Errorf("unsupported signature algorithm: %v", signatureAlgorithm) |
| 125 | } |
| 126 | return sigType, hash, nil |
| 127 | } |
| 128 | |
| 129 | // legacyTypeAndHashFromPublicKey returns the fixed signature type and crypto.Hash for |
| 130 | // a given public key used with TLS 1.0 and 1.1, before the introduction of |
no outgoing calls
no test coverage detected
searching dependent graphs…