Files
did-it/crypto/private.go

59 lines
1.8 KiB
Go
Raw Permalink Normal View History

package crypto
2025-07-30 18:32:14 +02:00
import "github.com/ucan-wg/go-varsig"
2025-07-03 15:55:58 +02:00
type PrivateKey interface {
// Equal returns true if other is the same PrivateKey
Equal(other PrivateKey) bool
// Public returns the matching PublicKey.
Public() PublicKey
// ToPKCS8DER serializes the PrivateKey into the PKCS#8 DER (binary) format.
ToPKCS8DER() []byte
// ToPKCS8PEM serializes the PrivateKey into the PKCS#8 PEM (string) format.
ToPKCS8PEM() string
}
2025-07-03 15:55:58 +02:00
type PrivateKeyToBytes interface {
PrivateKey
2025-07-03 15:55:58 +02:00
// ToBytes serializes the PrivateKey into "raw bytes", without metadata or structure.
// This format can make some assumptions and may not be what you expect.
// Ideally, this format is defined by the same specification as the underlying crypto scheme.
2025-07-03 15:55:58 +02:00
ToBytes() []byte
}
2025-07-09 17:58:09 +02:00
type PrivateKeySigningBytes interface {
PrivateKey
2025-07-30 18:32:14 +02:00
// Varsig returns the varsig.Varsig corresponding to the given parameters and private key.
Varsig(opts ...SigningOption) varsig.Varsig
// SignToBytes creates a signature in the "raw bytes" format.
// This format can make some assumptions and may not be what you expect.
// Ideally, this format is defined by the same specification as the underlying crypto scheme.
SignToBytes(message []byte, opts ...SigningOption) ([]byte, error)
2025-07-09 17:58:09 +02:00
}
type PrivateKeySigningASN1 interface {
PrivateKey
2025-07-30 18:32:14 +02:00
// Varsig returns the varsig.Varsig corresponding to the given parameters and private key.
Varsig(opts ...SigningOption) varsig.Varsig
// SignToASN1 creates a signature in the ASN.1 format.
SignToASN1(message []byte, opts ...SigningOption) ([]byte, error)
}
2025-07-03 15:55:58 +02:00
type PrivateKeyKeyExchange interface {
PrivateKey
// PublicKeyIsCompatible checks that the given PublicKey is compatible to perform key exchange.
PublicKeyIsCompatible(remote PublicKey) bool
// KeyExchange computes the shared key using the given PublicKey.
KeyExchange(remote PublicKey) ([]byte, error)
}