Source File
crypto.go
Belonging Package
github.com/libp2p/go-libp2p/p2p/security/noise
package noiseimport ()// encrypt calls the cipher's encryption. It encrypts the provided plaintext,// slice-appending the ciphertext on out.//// Usually you want to pass a 0-len slice to this method, with enough capacity// to accommodate the ciphertext in order to spare allocs.//// encrypt returns a new slice header, whose len is the length of the resulting// ciphertext, including the authentication tag.//// This method will not allocate if the supplied slice is large enough to// accommodate the encrypted data + authentication tag. If so, the returned// slice header should be a view of the original slice.//// With the poly1305 MAC function that noise-libp2p uses, the authentication tag// adds an overhead of 16 bytes.func ( *secureSession) (, []byte) ([]byte, error) {if .enc == nil {return nil, errors.New("cannot encrypt, handshake incomplete")}return .enc.Encrypt(, nil, )}// decrypt calls the cipher's decryption. It decrypts the provided ciphertext,// slice-appending the plaintext on out.//// Usually you want to pass a 0-len slice to this method, with enough capacity// to accommodate the plaintext in order to spare allocs.//// decrypt returns a new slice header, whose len is the length of the resulting// plaintext, without the authentication tag.//// This method will not allocate if the supplied slice is large enough to// accommodate the plaintext. If so, the returned slice header should be a view// of the original slice.func ( *secureSession) (, []byte) ([]byte, error) {if .dec == nil {return nil, errors.New("cannot decrypt, handshake incomplete")}return .dec.Decrypt(, nil, )}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |