fix go evt problem
Go vet reported a problem with the interface of WriteTo returning an int. Line 13: method WriteTo(stream io.Writer) (int, error) should have signature WriteTo(io.Writer) (int64, error) To fix that problem, the interface was changed to return io.WriterTo, which uses int64 for return values.
This commit is contained in:
parent
a11b67a64e
commit
11423e25b5
9
ecdsa.go
9
ecdsa.go
|
@ -9,6 +9,7 @@ import (
|
|||
"encoding/asn1"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
"io"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
|
@ -72,11 +73,11 @@ 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() (marshalledPemBlock, error) {
|
||||
func (pr EcdsaPrivateKey) MarshalPem() (io.WriterTo, error) {
|
||||
asn1, err := x509.MarshalECPrivateKey(pr.private_key)
|
||||
if err != nil { return nil, err }
|
||||
pem_block := pem.Block{Type: PemLabelEcdsa, Bytes: asn1}
|
||||
return pem.EncodeToMemory(&pem_block), nil
|
||||
return marshalledPemBlock(pem.EncodeToMemory(&pem_block)), nil
|
||||
}
|
||||
|
||||
// This functoin loads an ecdsa public key from the asn.1 representation.
|
||||
|
@ -91,11 +92,11 @@ func LoadPublicKeyEcdsa(raw []byte) (*EcdsaPublicKey, error) {
|
|||
|
||||
// This function implements the Pemmer interface to marshal the public key into
|
||||
// a pem block.
|
||||
func (pu *EcdsaPublicKey) MarshalPem() (marshalledPemBlock, error) {
|
||||
func (pu *EcdsaPublicKey) MarshalPem() (io.WriterTo, 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
|
||||
return marshalledPemBlock(pem.EncodeToMemory(&pem_block)), nil
|
||||
}
|
||||
|
||||
// This function verifies a message using the public key, signature and hash
|
||||
|
|
|
@ -10,6 +10,7 @@ type (
|
|||
|
||||
// This function writes the marshalled pem block to a writer and returns the
|
||||
// number of written bytes and eventual errors.
|
||||
func (b marshalledPemBlock) WriteTo(stream io.Writer) (int, error) {
|
||||
return stream.Write(b)
|
||||
func (b marshalledPemBlock) WriteTo(stream io.Writer) (int64, error) {
|
||||
numBytes, err := stream.Write(b)
|
||||
return int64(numBytes), err
|
||||
}
|
||||
|
|
9
rsa.go
9
rsa.go
|
@ -7,6 +7,7 @@ import (
|
|||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -50,10 +51,10 @@ func (pr RsaPrivateKey) PrivateKey() crypto.PrivateKey {
|
|||
return pr.private_key
|
||||
}
|
||||
|
||||
func (pr RsaPrivateKey) MarshalPem() (marshalledPemBlock, error) {
|
||||
func (pr RsaPrivateKey) MarshalPem() (io.WriterTo, error) {
|
||||
asn1 := x509.MarshalPKCS1PrivateKey(pr.private_key)
|
||||
pem_block := pem.Block{Type: PemLabelRsa, Bytes: asn1}
|
||||
return pem.EncodeToMemory(&pem_block), nil
|
||||
return marshalledPemBlock(pem.EncodeToMemory(&pem_block)), nil
|
||||
}
|
||||
|
||||
// restore a rsa public key
|
||||
|
@ -62,11 +63,11 @@ func LoadPublicKeyRsa(raw []byte) (*RsaPublicKey, error) {
|
|||
}
|
||||
|
||||
// marshal a rsa public key into pem format
|
||||
func (pu *RsaPublicKey) MarshalPem() (marshalledPemBlock, error) {
|
||||
func (pu *RsaPublicKey) MarshalPem() (io.WriterTo, 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
|
||||
return marshalledPemBlock(pem.EncodeToMemory(&pem_block)), nil
|
||||
}
|
||||
|
||||
// verify a message with a signature using the public key
|
||||
|
|
3
types.go
3
types.go
|
@ -16,6 +16,7 @@ package pki
|
|||
|
||||
import (
|
||||
"crypto"
|
||||
"io"
|
||||
)
|
||||
|
||||
// This label is used as the type in the pem encoding of public keys.
|
||||
|
@ -47,6 +48,6 @@ type (
|
|||
// in the pem format. The result can then be written to any structure
|
||||
// implementing the io.Writer interface.
|
||||
Pemmer interface {
|
||||
MarshalPem() (marshalledPemBlock, error)
|
||||
MarshalPem() (io.WriterTo, error)
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue