tests: compare RSA priv keys ignoring precomputed (#2481)

This commit is contained in:
Daniel McCarney 2025-03-15 08:26:09 -04:00 committed by GitHub
commit eb48c607ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -168,10 +168,12 @@ func TestParsePEMPrivateKey(t *testing.T) {
pemPrivateKey := PEMEncode(privateKey)
// Decoding a key should work and create an identical key to the original
// Decoding a key should work and create an identical RSA key to the original,
// ignoring precomputed values.
decoded, err := ParsePEMPrivateKey(pemPrivateKey)
require.NoError(t, err)
assert.Equal(t, decoded, privateKey)
decodedRsaPrivateKey := decoded.(*rsa.PrivateKey)
require.True(t, decodedRsaPrivateKey.Equal(privateKey))
// Decoding a PEM block that doesn't contain a private key should error
_, err = ParsePEMPrivateKey(pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE"}))