aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ecdsa.go10
-rw-r--r--pem_marshal.go2
-rw-r--r--rsa.go6
-rw-r--r--types.go5
4 files changed, 19 insertions, 4 deletions
diff --git a/ecdsa.go b/ecdsa.go
index 170786b..f8f51b2 100644
--- a/ecdsa.go
+++ b/ecdsa.go
@@ -1,4 +1,4 @@
-package pkilib
+package pki
import (
"crypto"
@@ -63,6 +63,14 @@ func (pr EcdsaPrivateKey) MarshalPem() (marshalledPemBlock, error) {
return pem.EncodeToMemory(&pem_block), nil
}
+// marshal the public key to a pem block
+func (pu *EcdsaPublicKey) MarshalPem() (marshalledPemBlock, error) {
+ asn1, err := x509.MarshalPKIXPublicKey(pu.public_key)
+ if err != nil { return nil, err }
+ pem_block := pem.Block{Type: PemLabelPublic, Bytes: asn1}
+ return pem.EncodeToMemory(&pem_block), nil
+}
+
// verify a message using the ecdsa public key
func (pu *EcdsaPublicKey) Verify(message []byte, signature []byte) (bool, error) {
return false, errors.New("not implemented yet!")
diff --git a/pem_marshal.go b/pem_marshal.go
index c9be63d..14b3bd4 100644
--- a/pem_marshal.go
+++ b/pem_marshal.go
@@ -1,4 +1,4 @@
-package pkilib
+package pki
import (
"io"
diff --git a/rsa.go b/rsa.go
index 48135b2..69e0a16 100644
--- a/rsa.go
+++ b/rsa.go
@@ -1,4 +1,4 @@
-package pkilib
+package pki
import (
"crypto"
@@ -49,6 +49,10 @@ func (pr RsaPrivateKey) MarshalPem() (marshalledPemBlock, error) {
return nil, errors.New("not implemented yet!")
}
+func (pu *RsaPublicKey) MarshalPem() (marshalledPemBlock, error) {
+ return nil, errors.New("not implemented yet!")
+}
+
func (pu *RsaPublicKey) Verify(message []byte, signature []byte) (bool, error) {
return false, errors.New("not implemented yet!")
}
diff --git a/types.go b/types.go
index e9326ee..b05bd40 100644
--- a/types.go
+++ b/types.go
@@ -1,4 +1,4 @@
-package pkilib
+package pki
import (
"crypto"
@@ -7,6 +7,8 @@ import (
// this file holds all the interfaces used in the program until it can be split
// properly
+const PemLabelPublic = "PUBLIC KEY"
+
type (
// interface for any private key
PrivateKey interface {
@@ -21,6 +23,7 @@ type (
// interface for any public key
PublicKey interface {
+ Pemmer
// use the public key to verify a message against a signature
Verify(message []byte, signature []byte) (bool, error)
}