diff options
author | Yawning Angel <yawning@schwanenlied.me> | 2014-05-12 04:51:06 +0000 |
---|---|---|
committer | Yawning Angel <yawning@schwanenlied.me> | 2014-05-12 04:51:06 +0000 |
commit | 9712aec73b2b483a4426ca670ee208b44ad1bc25 (patch) | |
tree | 9f46805aa32166d627e8038ddfd308b2f078bf99 /framing | |
parent | 8a1f58cd5a1e2345b7321259c074c044a0ecbefd (diff) |
Preliminary support padding, log on panic.
This adds preliminary support for data padding by adding another layer
of encapsulation inside each AEAD frame containing a type and length.
For now, data is still sent unpadded, but the infrastructure for
supporting it is mostly there.
Additionally, use log.Panic[f]() instead of panic through out the code
so that some panics are logged.
Diffstat (limited to 'framing')
-rw-r--r-- | framing/framing.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/framing/framing.go b/framing/framing.go index 5554a6e..75b9a73 100644 --- a/framing/framing.go +++ b/framing/framing.go @@ -61,6 +61,7 @@ import ( "errors" "fmt" "hash" + "log" "code.google.com/p/go.crypto/nacl/secretbox" @@ -126,7 +127,7 @@ type boxNonce struct { func (nonce *boxNonce) init(prefix []byte) { if noncePrefixLength != len(prefix) { - panic(fmt.Sprintf("BUG: Nonce prefix length invalid: %d", len(prefix))) + log.Panicf("BUG: Nonce prefix length invalid: %d", len(prefix)) } copy(nonce.prefix[:], prefix) @@ -160,7 +161,7 @@ type Encoder struct { // containing exactly KeyLength bytes of keying material. func NewEncoder(key []byte) *Encoder { if len(key) != KeyLength { - panic(fmt.Sprintf("BUG: Invalid encoder key length: %d", len(key))) + log.Panicf("BUG: Invalid encoder key length: %d", len(key)) } encoder := new(Encoder) @@ -222,7 +223,7 @@ type Decoder struct { // containing exactly KeyLength bytes of keying material. func NewDecoder(key []byte) *Decoder { if len(key) != KeyLength { - panic(fmt.Sprintf("BUG: Invalid decoder key length: %d", len(key))) + log.Panicf("BUG: Invalid decoder key length: %d", len(key)) } decoder := new(Decoder) @@ -252,7 +253,7 @@ func (decoder *Decoder) Decode(data *bytes.Buffer) (int, []byte, error) { return 0, nil, err } else if n != lengthLength { // Should *NEVER* happen, since at least 2 bytes exist. - panic(fmt.Sprintf("BUG: Failed to read obfuscated length: %d", n)) + log.Panicf("BUG: Failed to read obfuscated length: %d", n) } // Derive the nonce the peer used. @@ -284,8 +285,8 @@ func (decoder *Decoder) Decode(data *bytes.Buffer) (int, []byte, error) { return 0, nil, err } else if n != int(decoder.nextLength) { // Should *NEVER* happen, since at least 2 bytes exist. - panic(fmt.Sprintf("BUG: Failed to read secretbox, got %d, should have %d", n, - decoder.nextLength)) + log.Panicf("BUG: Failed to read secretbox, got %d, should have %d", n, + decoder.nextLength) } out, ok := secretbox.Open(nil, box, &decoder.nextNonce, &decoder.key) if !ok { |