1- // Copyright 2022 The NATS Authors
1+ // Copyright 2022-2023 The NATS Authors
22// Licensed under the Apache License, Version 2.0 (the "License");
33// you may not use this file except in compliance with the License.
44// You may obtain a copy of the License at
@@ -38,12 +38,13 @@ type ckp struct {
3838 seed [curveKeyLen ]byte // Private raw key.
3939}
4040
41- // CreateUser will create a User typed KeyPair.
41+ // CreateCurveKeys will create a Curve typed KeyPair.
4242func CreateCurveKeys () (KeyPair , error ) {
4343 return CreateCurveKeysWithRand (rand .Reader )
4444}
4545
46- // CreateUser will create a User typed KeyPair with specified rand source.
46+ // CreateCurveKeysWithRand will create a Curve typed KeyPair
47+ // with specified rand source.
4748func CreateCurveKeysWithRand (rr io.Reader ) (KeyPair , error ) {
4849 var kp ckp
4950 _ , err := io .ReadFull (rr , kp .seed [:])
@@ -85,7 +86,7 @@ func (pair *ckp) PrivateKey() ([]byte, error) {
8586 return Encode (PrefixBytePrivate , pair .seed [:])
8687}
8788
88- func decodePubCurveKey (src string , dest [curveKeyLen ]byte ) error {
89+ func decodePubCurveKey (src string , dest []byte ) error {
8990 var raw [curveDecodeLen ]byte // should always be 35
9091 n , err := b32Enc .Decode (raw [:], []byte (src ))
9192 if err != nil {
@@ -112,7 +113,7 @@ func decodePubCurveKey(src string, dest [curveKeyLen]byte) error {
112113 }
113114
114115 // Copy over, ignore prefix byte.
115- copy (dest [:] , raw [1 :end ])
116+ copy (dest , raw [1 :end ])
116117 return nil
117118}
118119
@@ -134,7 +135,7 @@ func (pair *ckp) SealWithRand(input []byte, recipient string, rr io.Reader) ([]b
134135 err error
135136 )
136137
137- if err = decodePubCurveKey (recipient , rpub ); err != nil {
138+ if err = decodePubCurveKey (recipient , rpub [:] ); err != nil {
138139 return nil , ErrInvalidRecipient
139140 }
140141 if _ , err := io .ReadFull (rr , nonce [:]); err != nil {
@@ -159,7 +160,7 @@ func (pair *ckp) Open(input []byte, sender string) ([]byte, error) {
159160 }
160161 copy (nonce [:], input [vlen :vlen + curveNonceLen ])
161162
162- if err = decodePubCurveKey (sender , spub ); err != nil {
163+ if err = decodePubCurveKey (sender , spub [:] ); err != nil {
163164 return nil , ErrInvalidSender
164165 }
165166
0 commit comments