2025-06-19 18:17:54 +02:00
|
|
|
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
|
|
|
|
2025-06-19 18:17:54 +02:00
|
|
|
type PrivateKey interface {
|
2025-06-24 14:05:42 +02:00
|
|
|
// Equal returns true if other is the same PrivateKey
|
2025-06-19 18:17:54 +02:00
|
|
|
Equal(other PrivateKey) bool
|
2025-06-24 14:05:42 +02:00
|
|
|
|
|
|
|
|
// Public returns the matching PublicKey.
|
2025-06-19 18:17:54 +02:00
|
|
|
Public() PublicKey
|
|
|
|
|
|
2025-06-24 14:05:42 +02:00
|
|
|
// ToPKCS8DER serializes the PrivateKey into the PKCS#8 DER (binary) format.
|
2025-06-19 18:17:54 +02:00
|
|
|
ToPKCS8DER() []byte
|
2025-06-24 14:05:42 +02:00
|
|
|
|
|
|
|
|
// ToPKCS8PEM serializes the PrivateKey into the PKCS#8 PEM (string) format.
|
2025-06-19 18:17:54 +02:00
|
|
|
ToPKCS8PEM() string
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-03 15:55:58 +02:00
|
|
|
type PrivateKeyToBytes interface {
|
|
|
|
|
PrivateKey
|
2025-06-19 18:17:54 +02:00
|
|
|
|
2025-07-03 15:55:58 +02:00
|
|
|
// ToBytes serializes the PrivateKey into "raw bytes", without metadata or structure.
|
2025-06-24 14:05:42 +02:00
|
|
|
// 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-06-19 18:17:54 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-09 17:58:09 +02:00
|
|
|
type PrivateKeySigningBytes interface {
|
2025-06-19 18:17:54 +02:00
|
|
|
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
|
|
|
|
|
|
2025-06-24 14:05:42 +02:00
|
|
|
// 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.
|
2025-07-08 12:57:06 +02:00
|
|
|
SignToBytes(message []byte, opts ...SigningOption) ([]byte, error)
|
2025-07-09 17:58:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PrivateKeySigningASN1 interface {
|
|
|
|
|
PrivateKey
|
2025-06-24 14:05:42 +02:00
|
|
|
|
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
|
|
|
|
|
|
2025-06-24 14:05:42 +02:00
|
|
|
// SignToASN1 creates a signature in the ASN.1 format.
|
2025-07-08 12:57:06 +02:00
|
|
|
SignToASN1(message []byte, opts ...SigningOption) ([]byte, error)
|
2025-06-19 18:17:54 +02:00
|
|
|
}
|
|
|
|
|
|
2025-07-03 15:55:58 +02:00
|
|
|
type PrivateKeyKeyExchange interface {
|
2025-06-24 14:05:42 +02:00
|
|
|
PrivateKey
|
2025-06-19 18:17:54 +02:00
|
|
|
|
2025-06-24 14:05:42 +02:00
|
|
|
// PublicKeyIsCompatible checks that the given PublicKey is compatible to perform key exchange.
|
|
|
|
|
PublicKeyIsCompatible(remote PublicKey) bool
|
2025-06-19 18:17:54 +02:00
|
|
|
|
2025-06-24 14:05:42 +02:00
|
|
|
// KeyExchange computes the shared key using the given PublicKey.
|
|
|
|
|
KeyExchange(remote PublicKey) ([]byte, error)
|
2025-06-19 18:17:54 +02:00
|
|
|
}
|