Skip to content
Snippets Groups Projects
Commit db69b3c0 authored by David Stainton's avatar David Stainton
Browse files

signature/rsa: use ELength const

parent be2aba7f
No related branches found
No related tags found
2 merge requests!23Channels Implementation,!21Add PublicKey's Bytes and FromBytes + tests
...@@ -30,7 +30,7 @@ import ( ...@@ -30,7 +30,7 @@ import (
const ( const (
// Elength is the length is bytes that the RSA Public Key's E component serializes to. // Elength is the length is bytes that the RSA Public Key's E component serializes to.
ELength = 8 ELength = 4
) )
// Key length used in the system in bits // Key length used in the system in bits
...@@ -141,17 +141,17 @@ func (p *PrivateKey) GetE() int { ...@@ -141,17 +141,17 @@ func (p *PrivateKey) GetE() int {
// in Bytes format. We chose the 32 bit integer for E // in Bytes format. We chose the 32 bit integer for E
// because it should be big enough. // because it should be big enough.
func (p *PublicKey) Bytes() []byte { func (p *PublicKey) Bytes() []byte {
buf := make([]byte, 4) buf := make([]byte, ELength)
binary.BigEndian.PutUint32(buf, uint32(p.GetE())) binary.BigEndian.PutUint32(buf, uint32(p.GetE()))
return append(buf, p.PublicKey.N.Bytes()...) return append(buf, p.PublicKey.N.Bytes()...)
} }
// FromBytes loads the given byte slice into the PublicKey. // FromBytes loads the given byte slice into the PublicKey.
func (p *PublicKey) FromBytes(b []byte) error { func (p *PublicKey) FromBytes(b []byte) error {
e := binary.BigEndian.Uint32(b[:4]) e := binary.BigEndian.Uint32(b[:ELength])
p.E = int(e) p.E = int(e)
p.N = new(big.Int) p.N = new(big.Int)
p.N.SetBytes(b[4:]) p.N.SetBytes(b[ELength:])
return nil return nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment