typeAndHashFromSignatureScheme returns the corresponding signature type and crypto.Hash for a given TLS SignatureScheme.
(signatureAlgorithm SignatureScheme)
| 96 | // typeAndHashFromSignatureScheme returns the corresponding signature type and |
| 97 | // crypto.Hash for a given TLS SignatureScheme. |
| 98 | func typeAndHashFromSignatureScheme(signatureAlgorithm SignatureScheme) (sigType uint8, hash crypto.Hash, err error) { |
| 99 | switch signatureAlgorithm { |
| 100 | case PKCS1WithSHA1, PKCS1WithSHA256, PKCS1WithSHA384, PKCS1WithSHA512: |
| 101 | sigType = signaturePKCS1v15 |
| 102 | case PSSWithSHA256, PSSWithSHA384, PSSWithSHA512: |
| 103 | sigType = signatureRSAPSS |
| 104 | case ECDSAWithSHA1, ECDSAWithP256AndSHA256, ECDSAWithP384AndSHA384, ECDSAWithP521AndSHA512: |
| 105 | sigType = signatureECDSA |
| 106 | case Ed25519: |
| 107 | sigType = signatureEd25519 |
| 108 | default: |
| 109 | return 0, 0, fmt.Errorf("unsupported signature algorithm: %v", signatureAlgorithm) |
| 110 | } |
| 111 | switch signatureAlgorithm { |
| 112 | case PKCS1WithSHA1, ECDSAWithSHA1: |
| 113 | hash = crypto.SHA1 |
| 114 | case PKCS1WithSHA256, PSSWithSHA256, ECDSAWithP256AndSHA256: |
| 115 | hash = crypto.SHA256 |
| 116 | case PKCS1WithSHA384, PSSWithSHA384, ECDSAWithP384AndSHA384: |
| 117 | hash = crypto.SHA384 |
| 118 | case PKCS1WithSHA512, PSSWithSHA512, ECDSAWithP521AndSHA512: |
| 119 | hash = crypto.SHA512 |
| 120 | case Ed25519: |
| 121 | hash = directSigning |
| 122 | default: |
| 123 | return 0, 0, fmt.Errorf("unsupported signature algorithm: %v", signatureAlgorithm) |
| 124 | } |
| 125 | return sigType, hash, nil |
| 126 | } |
| 127 | |
| 128 | // legacyTypeAndHashFromPublicKey returns the fixed signature type and crypto.Hash for |
| 129 | // 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…