-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Update to draft-ietf-openpgp-persistent-symmetric-keys-00"
This reverts commit 99debaa.
- Loading branch information
Showing
19 changed files
with
334 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package encoding | ||
|
||
import ( | ||
"io" | ||
) | ||
|
||
type ShortByteString struct { | ||
length uint8 | ||
data []byte | ||
} | ||
|
||
func NewShortByteString(data []byte) *ShortByteString { | ||
byteLength := uint8(len(data)) | ||
|
||
return &ShortByteString{byteLength, data} | ||
} | ||
|
||
func (byteString *ShortByteString) Bytes() []byte { | ||
return byteString.data | ||
} | ||
|
||
func (byteString *ShortByteString) BitLength() uint16 { | ||
return uint16(byteString.length) * 8 | ||
} | ||
|
||
func (byteString *ShortByteString) EncodedBytes() []byte { | ||
encodedLength := [1]byte{ | ||
uint8(byteString.length), | ||
} | ||
return append(encodedLength[:], byteString.data...) | ||
} | ||
|
||
func (byteString *ShortByteString) EncodedLength() uint16 { | ||
return uint16(byteString.length) + 1 | ||
} | ||
|
||
func (byteString *ShortByteString) ReadFrom(r io.Reader) (int64, error) { | ||
var lengthBytes [1]byte | ||
if n, err := io.ReadFull(r, lengthBytes[:]); err != nil { | ||
return int64(n), err | ||
} | ||
|
||
byteString.length = uint8(lengthBytes[0]) | ||
|
||
byteString.data = make([]byte, byteString.length) | ||
if n, err := io.ReadFull(r, byteString.data); err != nil { | ||
return int64(n + 1), err | ||
} | ||
return int64(byteString.length + 1), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package encoding | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
var octetStreamTests = []struct { | ||
data []byte | ||
}{ | ||
{ | ||
data: []byte{0x0, 0x0, 0x0}, | ||
}, | ||
{ | ||
data: []byte{0x1, 0x2, 0x03}, | ||
}, | ||
{ | ||
data: make([]byte, 255), | ||
}, | ||
} | ||
|
||
func TestShortByteString(t *testing.T) { | ||
for i, test := range octetStreamTests { | ||
octetStream := NewShortByteString(test.data) | ||
|
||
if b := octetStream.Bytes(); !bytes.Equal(b, test.data) { | ||
t.Errorf("#%d: bad creation got:%x want:%x", i, b, test.data) | ||
} | ||
|
||
expectedBitLength := uint16(len(test.data)) * 8 | ||
if bitLength := octetStream.BitLength(); bitLength != expectedBitLength { | ||
t.Errorf("#%d: bad bit length got:%d want :%d", i, bitLength, expectedBitLength) | ||
} | ||
|
||
expectedEncodedLength := uint16(len(test.data)) + 1 | ||
if encodedLength := octetStream.EncodedLength(); encodedLength != expectedEncodedLength { | ||
t.Errorf("#%d: bad encoded length got:%d want:%d", i, encodedLength, expectedEncodedLength) | ||
} | ||
|
||
encodedBytes := octetStream.EncodedBytes() | ||
if !bytes.Equal(encodedBytes[1:], test.data) { | ||
t.Errorf("#%d: bad encoded bytes got:%x want:%x", i, encodedBytes[1:], test.data) | ||
} | ||
|
||
encodedLength := int(encodedBytes[0]) | ||
if encodedLength != len(test.data) { | ||
t.Errorf("#%d: bad encoded length got:%d want%d", i, encodedLength, len(test.data)) | ||
} | ||
|
||
newStream := new(ShortByteString) | ||
newStream.ReadFrom(bytes.NewReader(encodedBytes)) | ||
|
||
if !checkEquality(newStream, octetStream) { | ||
t.Errorf("#%d: bad parsing of encoded octet stream", i) | ||
} | ||
} | ||
} | ||
|
||
func checkEquality(left *ShortByteString, right *ShortByteString) bool { | ||
return (left.length == right.length) && (bytes.Equal(left.data, right.data)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.