add pem support to public key
This adds pem support to public keys which can now be handled the same way as private keys.
This commit is contained in:
parent
930035ce91
commit
53327f7467
10
ecdsa.go
10
ecdsa.go
|
@ -1,4 +1,4 @@
|
||||||
package pkilib
|
package pki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto"
|
"crypto"
|
||||||
|
@ -63,6 +63,14 @@ func (pr EcdsaPrivateKey) MarshalPem() (marshalledPemBlock, error) {
|
||||||
return pem.EncodeToMemory(&pem_block), nil
|
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
|
// verify a message using the ecdsa public key
|
||||||
func (pu *EcdsaPublicKey) Verify(message []byte, signature []byte) (bool, error) {
|
func (pu *EcdsaPublicKey) Verify(message []byte, signature []byte) (bool, error) {
|
||||||
return false, errors.New("not implemented yet!")
|
return false, errors.New("not implemented yet!")
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package pkilib
|
package pki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
|
6
rsa.go
6
rsa.go
|
@ -1,4 +1,4 @@
|
||||||
package pkilib
|
package pki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto"
|
"crypto"
|
||||||
|
@ -49,6 +49,10 @@ func (pr RsaPrivateKey) MarshalPem() (marshalledPemBlock, error) {
|
||||||
return nil, errors.New("not implemented yet!")
|
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) {
|
func (pu *RsaPublicKey) Verify(message []byte, signature []byte) (bool, error) {
|
||||||
return false, errors.New("not implemented yet!")
|
return false, errors.New("not implemented yet!")
|
||||||
}
|
}
|
||||||
|
|
5
types.go
5
types.go
|
@ -1,4 +1,4 @@
|
||||||
package pkilib
|
package pki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto"
|
"crypto"
|
||||||
|
@ -7,6 +7,8 @@ import (
|
||||||
// this file holds all the interfaces used in the program until it can be split
|
// this file holds all the interfaces used in the program until it can be split
|
||||||
// properly
|
// properly
|
||||||
|
|
||||||
|
const PemLabelPublic = "PUBLIC KEY"
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// interface for any private key
|
// interface for any private key
|
||||||
PrivateKey interface {
|
PrivateKey interface {
|
||||||
|
@ -21,6 +23,7 @@ type (
|
||||||
|
|
||||||
// interface for any public key
|
// interface for any public key
|
||||||
PublicKey interface {
|
PublicKey interface {
|
||||||
|
Pemmer
|
||||||
// use the public key to verify a message against a signature
|
// use the public key to verify a message against a signature
|
||||||
Verify(message []byte, signature []byte) (bool, error)
|
Verify(message []byte, signature []byte) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue