Skip to content

Commit

Permalink
go: drop SerializeSCTList() entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddrysdale committed Dec 6, 2016
1 parent c022826 commit 68e9dee
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 61 deletions.
29 changes: 0 additions & 29 deletions serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"container/list"
"crypto"
"encoding/asn1"
"encoding/binary"
"encoding/json"
"errors"
Expand Down Expand Up @@ -542,34 +541,6 @@ func SCTListSerializedLength(scts []SignedCertificateTimestamp) (int, error) {
return sctListLen, nil
}

// SerializeSCTList serializes the passed-in slice of SignedCertificateTimestamp into a
// byte slice as a SignedCertificateTimestampList (see RFC6962 Section 3.3)
func SerializeSCTList(scts []SignedCertificateTimestamp) ([]byte, error) {
size, err := SCTListSerializedLength(scts)
if err != nil {
return nil, err
}
fullSize := 2 + size // 2 bytes for length + size of SCT list
if fullSize > MaxSCTListLength {
return nil, fmt.Errorf("SCT List too large to serialize: %d", fullSize)
}
buf := new(bytes.Buffer)
buf.Grow(fullSize)
if err = writeUint(buf, uint64(size), 2); err != nil {
return nil, err
}
for _, sct := range scts {
serialized, err := SerializeSCT(sct)
if err != nil {
return nil, err
}
if err = writeVarBytes(buf, serialized, 2); err != nil {
return nil, err
}
}
return asn1.Marshal(buf.Bytes()) // transform to Octet String
}

// CreateX509MerkleTreeLeaf generates a MerkleTreeLeaf for an X509 cert
func CreateX509MerkleTreeLeaf(cert ASN1Cert, timestamp uint64) *MerkleTreeLeaf {
return &MerkleTreeLeaf{
Expand Down
32 changes: 0 additions & 32 deletions serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,38 +479,6 @@ func TestSerializeSCT(t *testing.T) {
}
}

func TestSerializeSCTList(t *testing.T) {
b, err := SerializeSCTList([]SignedCertificateTimestamp{defaultSCT(), defaultSCT()})
if err != nil {
t.Fatalf("Failed to serialize SCT List: %v", err)
}
if bytes.Compare(mustDehex(t, defaultSCTListHexString), b) != 0 {
t.Fatalf("Serialized SCT differs from expected KA. Expected:\n%v\nGot:\n%v", mustDehex(t, defaultSCTListHexString), b)
}

// Test list too large
d := defaultSCT()
len, err := d.SerializedLength()
if err != nil {
t.Fatalf("SerializedLength failed: %s", err)
}
list := []SignedCertificateTimestamp{}
for l := 2; l < MaxSCTListLength; {
list = append(list, d)
l += len + 2
}
_, err = SerializeSCTList(list)
if err == nil {
t.Fatal("SerializeSCTList didn't fail with too large of a serialized SCT list")
}
// Test SCT too large
d.Extensions = make(CTExtensions, MaxSCTInListLength-len)
_, err = SerializeSCTList(list)
if err == nil {
t.Fatal("SerializeSCTList didn't fail with too large of a individual SCT")
}
}

func TestDeserializeSCT(t *testing.T) {
sct, err := DeserializeSCT(bytes.NewReader(mustDehex(t, defaultSCTHexString)))
if err != nil {
Expand Down

0 comments on commit 68e9dee

Please sign in to comment.