mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-15 00:31:30 -05:00
Bumps [github.com/open-policy-agent/opa](https://github.com/open-policy-agent/opa) from 1.8.0 to 1.9.0. - [Release notes](https://github.com/open-policy-agent/opa/releases) - [Changelog](https://github.com/open-policy-agent/opa/blob/main/CHANGELOG.md) - [Commits](https://github.com/open-policy-agent/opa/compare/v1.8.0...v1.9.0) --- updated-dependencies: - dependency-name: github.com/open-policy-agent/opa dependency-version: 1.9.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package dsig
|
|
|
|
import (
|
|
"crypto"
|
|
"crypto/ed25519"
|
|
"fmt"
|
|
)
|
|
|
|
func eddsaGetSigner(key any) (crypto.Signer, error) {
|
|
// The ed25519.PrivateKey object implements crypto.Signer, so we should
|
|
// simply accept a crypto.Signer here.
|
|
signer, ok := key.(crypto.Signer)
|
|
if ok {
|
|
if !isValidEDDSAKey(key) {
|
|
return nil, fmt.Errorf(`invalid key type %T for EdDSA algorithm`, key)
|
|
}
|
|
return signer, nil
|
|
}
|
|
|
|
// This fallback exists for cases when users give us a pointer instead of non-pointer, etc.
|
|
privkey, ok := key.(ed25519.PrivateKey)
|
|
if !ok {
|
|
return nil, fmt.Errorf(`failed to retrieve ed25519.PrivateKey out of %T`, key)
|
|
}
|
|
return privkey, nil
|
|
}
|
|
|
|
// SignEdDSA generates an EdDSA (Ed25519) signature for the given payload.
|
|
// The raw parameter should be the pre-computed signing input (typically header.payload).
|
|
// EdDSA is deterministic and doesn't require additional hashing of the input.
|
|
func SignEdDSA(key ed25519.PrivateKey, payload []byte) ([]byte, error) {
|
|
return ed25519.Sign(key, payload), nil
|
|
}
|
|
|
|
// VerifyEdDSA verifies an EdDSA (Ed25519) signature for the given payload.
|
|
// This function verifies the signature using Ed25519 verification algorithm.
|
|
// The payload parameter should be the pre-computed signing input (typically header.payload).
|
|
// EdDSA is deterministic and provides strong security guarantees without requiring hash function selection.
|
|
func VerifyEdDSA(key ed25519.PublicKey, payload, signature []byte) error {
|
|
if !ed25519.Verify(key, payload, signature) {
|
|
return fmt.Errorf("invalid EdDSA signature")
|
|
}
|
|
return nil
|
|
}
|