Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz834 committed Jun 20, 2023
1 parent 1edc57b commit 51139da
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/encoding/asn1/asn1.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,12 @@ var (
errInvalidOID = errors.New("invalid oid")
)

// An OID represents an ASN.1 OBJECT IDENTIFIER.
type OID struct {
der []byte
}

// FromObjectIdentifer created a new OID from ObjectIdentifier.
func FromObjectIdentifer(oid ObjectIdentifier) (OID, error) {
enc, err := makeObjectIdentifier(oid)
if err != nil {
Expand Down Expand Up @@ -342,12 +344,14 @@ func isDEROIDValid(der []byte) bool {
return true
}

// Equal returns true when oid and other represents the same Object Identifier.
func (oid OID) Equal(other OID) bool {
// There is only one possible DER encoding of
// each unique Object Identifier.
return bytes.Equal(oid.der, other.der)
}

// ToObjectIdentifer converts oid to an ObjectIdentifier.
func (oid OID) ToObjectIdentifer() (ObjectIdentifier, bool) {
o, err := parseObjectIdentifier(oid.der)
if err != nil {
Expand All @@ -356,6 +360,7 @@ func (oid OID) ToObjectIdentifer() (ObjectIdentifier, bool) {
return o, true
}

// Equal returns true when oid and other represents the same Object Identifier.
func (oid OID) EqualObjectIdentifer(other ObjectIdentifier) bool {
const (
valSize = 31
Expand Down Expand Up @@ -418,6 +423,7 @@ func (oid OID) EqualObjectIdentifer(other ObjectIdentifier) bool {
return true
}

// Strings returns the string representation of the Object Identifier.
func (oid OID) String() string {
var b strings.Builder
b.Grow(32)
Expand Down

0 comments on commit 51139da

Please sign in to comment.