mirror of
https://github.com/go-micro/go-micro.git
synced 2025-08-04 21:42:57 +02:00
fix: some linting issues (#2563)
This commit is contained in:
@ -18,7 +18,7 @@ type box struct {
|
||||
privateKey [keyLength]byte
|
||||
}
|
||||
|
||||
// NewSecrets returns a nacl-box codec
|
||||
// NewSecrets returns a nacl-box codec.
|
||||
func NewSecrets(opts ...secrets.Option) secrets.Secrets {
|
||||
b := &box{}
|
||||
for _, o := range opts {
|
||||
@ -27,7 +27,6 @@ func NewSecrets(opts ...secrets.Option) secrets.Secrets {
|
||||
return b
|
||||
}
|
||||
|
||||
// Init initialises a box
|
||||
func (b *box) Init(opts ...secrets.Option) error {
|
||||
for _, o := range opts {
|
||||
o(&b.options)
|
||||
@ -40,17 +39,17 @@ func (b *box) Init(opts ...secrets.Option) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Options returns options
|
||||
// Options returns options.
|
||||
func (b *box) Options() secrets.Options {
|
||||
return b.options
|
||||
}
|
||||
|
||||
// String returns nacl-box
|
||||
// String returns nacl-box.
|
||||
func (*box) String() string {
|
||||
return "nacl-box"
|
||||
}
|
||||
|
||||
// Encrypt encrypts a message with the sender's private key and the receipient's public key
|
||||
// Encrypt encrypts a message with the sender's private key and the receipient's public key.
|
||||
func (b *box) Encrypt(in []byte, opts ...secrets.EncryptOption) ([]byte, error) {
|
||||
var options secrets.EncryptOptions
|
||||
for _, o := range opts {
|
||||
@ -68,7 +67,7 @@ func (b *box) Encrypt(in []byte, opts ...secrets.EncryptOption) ([]byte, error)
|
||||
return naclbox.Seal(nonce[:], in, &nonce, &recipientPublicKey, &b.privateKey), nil
|
||||
}
|
||||
|
||||
// Decrypt Decrypts a message with the receiver's private key and the sender's public key
|
||||
// Decrypt Decrypts a message with the receiver's private key and the sender's public key.
|
||||
func (b *box) Decrypt(in []byte, opts ...secrets.DecryptOption) ([]byte, error) {
|
||||
var options secrets.DecryptOptions
|
||||
for _, o := range opts {
|
||||
|
@ -30,14 +30,14 @@ func TestBox(t *testing.T) {
|
||||
}
|
||||
aliceSecret := []byte("Why is a raven like a writing-desk?")
|
||||
if _, err := alice.Encrypt(aliceSecret); err == nil {
|
||||
t.Error("alice.Encrypt succeded without a public key")
|
||||
t.Error("alice.Encrypt succeeded without a public key")
|
||||
}
|
||||
enc, err := alice.Encrypt(aliceSecret, secrets.RecipientPublicKey(bob.Options().PublicKey))
|
||||
if err != nil {
|
||||
t.Error("alice.Encrypt failed")
|
||||
}
|
||||
if _, err := bob.Decrypt(enc); err == nil {
|
||||
t.Error("bob.Decrypt succeded without a public key")
|
||||
t.Error("bob.Decrypt succeeded without a public key")
|
||||
}
|
||||
if dec, err := bob.Decrypt(enc, secrets.SenderPublicKey(alice.Options().PublicKey)); err == nil {
|
||||
if !reflect.DeepEqual(dec, aliceSecret) {
|
||||
|
Reference in New Issue
Block a user