Skip to content

Commit

Permalink
Return nil instead of &trillian.LogLeaf{} when there is an err
Browse files Browse the repository at this point in the history
  • Loading branch information
roger2hk committed May 30, 2024
1 parent fd2ecd6 commit 274bf15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions trillian/ctfe/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,23 @@ func (s *issuanceChainService) BuildLogLeaf(ctx context.Context, chain []*x509.C
if s.isCTFEStorageEnabled() {
issuanceChain, err := asn1.Marshal(raw[1:])
if err != nil {
return &trillian.LogLeaf{}, fmt.Errorf("failed to marshal issuance chain: %s", err)
return nil, fmt.Errorf("failed to marshal issuance chain: %s", err)
}
hash, err := s.add(ctx, issuanceChain)
if err != nil {
return &trillian.LogLeaf{}, fmt.Errorf("failed to add issuance chain into CTFE storage: %s", err)
return nil, fmt.Errorf("failed to add issuance chain into CTFE storage: %s", err)
}
leaf, err := util.BuildLogLeafWithChainHash(logPrefix, *merkleLeaf, 0, raw[0], hash, isPrecert)
if err != nil {
return &trillian.LogLeaf{}, fmt.Errorf("failed to build LogLeaf: %s", err)
return nil, fmt.Errorf("failed to build LogLeaf: %s", err)
}
return leaf, nil
}

// Trillian gRPC
leaf, err := util.BuildLogLeaf(logPrefix, *merkleLeaf, 0, raw[0], raw[1:], isPrecert)
if err != nil {
return &trillian.LogLeaf{}, fmt.Errorf("failed to build LogLeaf: %s", err)
return nil, fmt.Errorf("failed to build LogLeaf: %s", err)
}
return leaf, nil

Expand Down
4 changes: 2 additions & 2 deletions trillian/util/log_leaf.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func buildLogLeaf(logPrefix string, merkleLeaf ct.MerkleTreeLeaf, leafIndex int6
leafData, err := tls.Marshal(merkleLeaf)
if err != nil {
klog.Warningf("%s: Failed to serialize Merkle leaf: %v", logPrefix, err)
return &trillian.LogLeaf{}, err
return nil, err
}

var extraData []byte
Expand All @@ -97,7 +97,7 @@ func buildLogLeaf(logPrefix string, merkleLeaf ct.MerkleTreeLeaf, leafIndex int6
}
if err != nil {
klog.Warningf("%s: Failed to serialize chain for ExtraData: %v", logPrefix, err)
return &trillian.LogLeaf{}, err
return nil, err
}
// leafIDHash allows Trillian to detect duplicate entries, so this should be
// a hash over the cert data.
Expand Down

0 comments on commit 274bf15

Please sign in to comment.