diff options
Diffstat (limited to 'framing/framing.go')
-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 { |