Skip to content

Commit 5625808

Browse files
committed
update docs for return values
1 parent 8929309 commit 5625808

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

nacl/box/box.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,39 +84,47 @@ func Precompute(sharedKey, peersPublicKey, privateKey *[32]byte) {
8484
}
8585

8686
// Seal appends an encrypted and authenticated copy of message to out, which
87-
// will be Overhead bytes longer than the original and must not overlap it. The
88-
// nonce must be unique for each distinct message for a given pair of keys.
87+
// will be Overhead bytes longer than the original and must not overlap it.
88+
// The return value is a slice containing the appended output, which may
89+
// point to a newly allocated buffer if out lacks sufficient capacity.
8990
func Seal(out, message []byte, nonce *[24]byte, peersPublicKey, privateKey *[32]byte) []byte {
9091
var sharedKey [32]byte
9192
Precompute(&sharedKey, peersPublicKey, privateKey)
9293
return secretbox.Seal(out, message, nonce, &sharedKey)
9394
}
9495

9596
// SealAfterPrecomputation performs the same actions as Seal, but takes a
96-
// shared key as generated by Precompute.
97+
// shared key as generated by Precompute. The return value is a slice containing
98+
// the appended output, which may point to a newly allocated buffer if out lacks
99+
// sufficient capacity.
97100
func SealAfterPrecomputation(out, message []byte, nonce *[24]byte, sharedKey *[32]byte) []byte {
98101
return secretbox.Seal(out, message, nonce, sharedKey)
99102
}
100103

101104
// Open authenticates and decrypts a box produced by Seal and appends the
102105
// message to out, which must not overlap box. The output will be Overhead
103-
// bytes smaller than box.
106+
// bytes smaller than box. The return value is the updated out slice containing
107+
// the decrypted message and a boolean indicating whether authentication was
108+
// successful.
104109
func Open(out, box []byte, nonce *[24]byte, peersPublicKey, privateKey *[32]byte) ([]byte, bool) {
105110
var sharedKey [32]byte
106111
Precompute(&sharedKey, peersPublicKey, privateKey)
107112
return secretbox.Open(out, box, nonce, &sharedKey)
108113
}
109114

110115
// OpenAfterPrecomputation performs the same actions as Open, but takes a
111-
// shared key as generated by Precompute.
116+
// shared key as generated by Precompute. The return value is the updated out
117+
// slice containing the decrypted message and a boolean indicating whether
118+
// authentication was successful.
112119
func OpenAfterPrecomputation(out, box []byte, nonce *[24]byte, sharedKey *[32]byte) ([]byte, bool) {
113120
return secretbox.Open(out, box, nonce, sharedKey)
114121
}
115122

116123
// SealAnonymous appends an encrypted and authenticated copy of message to out,
117124
// which will be AnonymousOverhead bytes longer than the original and must not
118125
// overlap it. This differs from Seal in that the sender is not required to
119-
// provide a private key.
126+
// provide a private key. The return value is the updated out slice containing
127+
// the appended output.
120128
func SealAnonymous(out, message []byte, recipient *[32]byte, rand io.Reader) ([]byte, error) {
121129
if rand == nil {
122130
rand = cryptorand.Reader

nacl/secretbox/secretbox.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ func sliceForAppend(in []byte, n int) (head, tail []byte) {
7272

7373
// Seal appends an encrypted and authenticated copy of message to out, which
7474
// must not overlap message. The key and nonce pair must be unique for each
75-
// distinct message and the output will be Overhead bytes longer than message.
75+
// distinct message. The output will be Overhead bytes longer than message.
76+
// The return value is a slice containing the entire output, which may point
77+
// to a newly allocated buffer if out lacks sufficient capacity.
7678
func Seal(out, message []byte, nonce *[24]byte, key *[32]byte) []byte {
7779
var subKey [32]byte
7880
var counter [16]byte
@@ -121,7 +123,10 @@ func Seal(out, message []byte, nonce *[24]byte, key *[32]byte) []byte {
121123

122124
// Open authenticates and decrypts a box produced by Seal and appends the
123125
// message to out, which must not overlap box. The output will be Overhead
124-
// bytes smaller than box.
126+
// bytes smaller than box. The return value is a slice containing the entire
127+
// output, which may point to a newly allocated buffer if out lacks sufficient
128+
// capacity, and a boolean indicating whether the authentication was
129+
// successful.
125130
func Open(out, box []byte, nonce *[24]byte, key *[32]byte) ([]byte, bool) {
126131
if len(box) < Overhead {
127132
return nil, false

nacl/sign/sign.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ func GenerateKey(rand io.Reader) (publicKey *[32]byte, privateKey *[64]byte, err
4444
}
4545

4646
// Sign appends a signed copy of message to out, which will be Overhead bytes
47-
// longer than the original and must not overlap it.
47+
// longer than the original and must not overlap it. The return value is a
48+
// slice containing the signed message, which may point to a newly allocated
49+
// buffer if out lacks sufficient capacity.
4850
func Sign(out, message []byte, privateKey *[64]byte) []byte {
4951
sig := ed25519.Sign(ed25519.PrivateKey((*privateKey)[:]), message)
5052
ret, out := sliceForAppend(out, Overhead+len(message))
@@ -58,7 +60,9 @@ func Sign(out, message []byte, privateKey *[64]byte) []byte {
5860

5961
// Open verifies a signed message produced by Sign and appends the message to
6062
// out, which must not overlap the signed message. The output will be Overhead
61-
// bytes smaller than the signed message.
63+
// bytes smaller than the signed message. The return values are the updated out
64+
// slice containing the verified message and a boolean indicating whether the
65+
// signature verification was successful.
6266
func Open(out, signedMessage []byte, publicKey *[32]byte) ([]byte, bool) {
6367
if len(signedMessage) < Overhead {
6468
return nil, false

0 commit comments

Comments
 (0)