Skip to content

Commit

Permalink
fix: simplify code
Browse files Browse the repository at this point in the history
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
  • Loading branch information
JeyJeyGao committed Aug 9, 2023
1 parent 75ce02d commit 4198690
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
5 changes: 2 additions & 3 deletions internal/encoding/asn1/asn1.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var (
ErrTrailingData = asn1.SyntaxError{Msg: "trailing data"}
ErrUnsupportedLength = asn1.StructuralError{Msg: "length method not supported"}
ErrUnsupportedIndefiniteLength = asn1.StructuralError{Msg: "indefinite length not supported"}
ErrUnsupportedValueType = asn1.StructuralError{Msg: "value type not supported"}
)

// value represents an ASN.1 value.
Expand Down Expand Up @@ -59,9 +58,9 @@ func ConvertToDER(ber []byte) ([]byte, error) {
return nil, err
}

if v.Content() != nil {
if content := v.Content(); content != nil {
// primitive value
_, err = buf.Write(v.Content())
_, err = buf.Write(content)
if err != nil {
return nil, err
}
Expand Down
5 changes: 1 addition & 4 deletions internal/encoding/asn1/constructed.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ func (v *constructedValue) EncodeMetadata(w *bytes.Buffer) error {
if err != nil {
return err
}
if err = encodeLength(w, v.length); err != nil {
return err
}
return nil
return encodeLength(w, v.length)
}

// EncodedLen returns the length in bytes of the encoded data.
Expand Down
5 changes: 1 addition & 4 deletions internal/encoding/asn1/primitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ func (v *primitiveValue) EncodeMetadata(w *bytes.Buffer) error {
if err != nil {
return err
}
if err = encodeLength(w, len(v.content)); err != nil {
return err
}
return nil
return encodeLength(w, len(v.content))
}

// EncodedLen returns the length in bytes of the encoded data.
Expand Down

0 comments on commit 4198690

Please sign in to comment.