aboutsummaryrefslogtreecommitdiff
path: root/ecdsa.go
diff options
context:
space:
mode:
authorGibheer <gibheer+git@zero-knowledge.org>2017-05-12 15:27:44 +0200
committerGibheer <gibheer+git@zero-knowledge.org>2017-05-12 15:27:44 +0200
commitb6c44317f540dac8763e720767b0e73940a0b6c5 (patch)
treefac6e911056ba12da589dac4ad1f32aa63430f78 /ecdsa.go
parentfd88bca2872e589b451cde3767dbc59d82bd1c83 (diff)
add proper pem interface
This should finally resolve the completely broken and wrong API to get a pem representation of a resource.
Diffstat (limited to 'ecdsa.go')
-rw-r--r--ecdsa.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/ecdsa.go b/ecdsa.go
index 66b73f5..8bf432d 100644
--- a/ecdsa.go
+++ b/ecdsa.go
@@ -78,14 +78,22 @@ func (pr EcdsaPrivateKey) PrivateKey() crypto.PrivateKey {
// This function implements the Pemmer interface to marshal the private key
// into a pem block.
func (pr EcdsaPrivateKey) MarshalPem() (io.WriterTo, error) {
- asn1, err := x509.MarshalECPrivateKey(pr.private_key)
+ pem_block, err := pr.ToPem()
if err != nil {
return nil, err
}
- pem_block := pem.Block{Type: PemLabelEcdsa, Bytes: asn1}
return marshalledPemBlock(pem.EncodeToMemory(&pem_block)), nil
}
+// This function implements ToPem to return the raw pem block.
+func (pr EcdsaPrivateKey) ToPem() (pem.Block, error) {
+ asn1, err := x509.MarshalECPrivateKey(pr.private_key)
+ if err != nil {
+ return pem.Block{}, err
+ }
+ return pem.Block{Type: PemLabelEcdsa, Bytes: asn1}, nil
+}
+
// This functoin loads an ecdsa public key from the asn.1 representation.
func LoadPublicKeyEcdsa(raw []byte) (*EcdsaPublicKey, error) {
raw_pub, err := x509.ParsePKIXPublicKey(raw)