Verifies the signature of the CSR. # Arguments `signature` - The signature bytes to verify against the CSR data. # Returns `Ok(())` if the signature is valid and the magic string matches. # Errors Returns an error if: - The public key cannot be parsed - The algorithm is not ECDSA P-256 - The signature is invalid - The magic string does not match "please sign cert:"
(&self, signature: &[u8])
| 229 | /// - The signature is invalid |
| 230 | /// - The magic string does not match "please sign cert:" |
| 231 | fn verify(&self, signature: &[u8]) -> Result<()> { |
| 232 | let encoded = self.data_to_sign(); |
| 233 | let (_rem, pki) = |
| 234 | SubjectPublicKeyInfo::from_der(self.pubkey()).context("Failed to parse pubkey")?; |
| 235 | let parsed_pki = pki.parsed().context("Failed to parse pki")?; |
| 236 | if !matches!(parsed_pki, PublicKey::EC(_)) { |
| 237 | bail!("Unsupported algorithm"); |
| 238 | } |
| 239 | let key = UnparsedPublicKey::new(&ECDSA_P256_SHA256_ASN1, &pki.subject_public_key.data); |
| 240 | // verify signature |
| 241 | key.verify(&encoded, signature) |
| 242 | .ok() |
| 243 | .context("Invalid signature")?; |
| 244 | if self.magic() != "please sign cert:" { |
| 245 | bail!("Invalid confirm word"); |
| 246 | } |
| 247 | Ok(()) |
| 248 | } |
| 249 | |
| 250 | /// Returns the data that should be signed or verified. |
| 251 | /// |
nothing calls this directly
no test coverage detected