nacl/secretbox: add license header and package prefix

Name the example package "secretbox_test" so we use the public
interface for secretbox in examples. This way the code appears the
same way a user would have to type it.

Change-Id: I0487e39927ddae297ea45e09a3fa397779a8e21d
Reviewed-on: https://go-review.googlesource.com/28222
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Kevin Burke 2016-08-30 23:05:48 -07:00 коммит произвёл Ian Lance Taylor
Родитель b13fc1fd38
Коммит 055d4bfb5c
1 изменённых файлов: 9 добавлений и 3 удалений

Просмотреть файл

@ -1,10 +1,16 @@
package secretbox
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package secretbox_test
import (
"crypto/rand"
"encoding/hex"
"fmt"
"io"
"golang.org/x/crypto/nacl/secretbox"
)
func Example() {
@ -29,7 +35,7 @@ func Example() {
}
// This encrypts "hello world" and appends the result to the nonce.
encrypted := Seal(nonce[:], []byte("hello world"), &nonce, &secretKey)
encrypted := secretbox.Seal(nonce[:], []byte("hello world"), &nonce, &secretKey)
// When you decrypt, you must use the same nonce and key you used to
// encrypt the message. One way to achieve this is to store the nonce
@ -37,7 +43,7 @@ func Example() {
// 24 bytes of the encrypted text.
var decryptNonce [24]byte
copy(decryptNonce[:], encrypted[:24])
decrypted, ok := Open([]byte{}, encrypted[24:], &decryptNonce, &secretKey)
decrypted, ok := secretbox.Open([]byte{}, encrypted[24:], &decryptNonce, &secretKey)
if !ok {
panic("decryption error")
}