ObjectIdentifier
internal struct ObjectIdentifier : Hashable
extension ObjectIdentifier: CustomStringConvertible
extension ObjectIdentifier: ExpressibleByStringLiteral
extension ObjectIdentifier: Equatable
The ObjectIdentifier
structure represents an Object Identifier (OID) commonly used
in various encoding and security protocols.
An OID is a sequence of integers separated by periods, used to uniquely identify objects in a hierarchical naming structure.
- Tip: The structure provides methods for creating, encoding, and working with OIDs. It also supports basic operations such as concatenation and checking if one OID starts with another.
-
Initializes an
ObjectIdentifier
with an array ofUInt8
values.Declaration
Swift
internal init(bytes: [UInt8])
Parameters
bytes
An array of
UInt8
values representing the OID. -
Initializes an
ObjectIdentifier
with a variadic list ofUInt8
values.Declaration
Swift
internal init(bytes: UInt8...)
Parameters
bytes
A list of
UInt8
values representing the OID. -
Initializes an
ObjectIdentifier
by extending an existingObjectIdentifier
with additionalUInt8
values.Declaration
Swift
internal init(_ initialValue: ObjectIdentifier, bytes: UInt8...)
Parameters
initialValue
The initial
ObjectIdentifier
to extend.bytes
A list of additional
UInt8
values to append. -
Initializes an
ObjectIdentifier
by decoding an array ofUInt8
values representing an ASN.1 encoded OID.Throws
An error if decoding or parsing the OID fails.
Declaration
Swift
internal init(encoded: [UInt8]) throws
Parameters
encoded
An array of
UInt8
values representing the encoded OID in ASN.1 format. -
Initializes an
ObjectIdentifier
based on an ASN.1 node representing an OID.Throws
An error if the provided
node
is not a valid ASN.1 OID.Declaration
Swift
internal init(node: ASN1Node) throws
Parameters
node
An
ASN1Node
representing an OID in ASN.1 format. -
Encodes the
ObjectIdentifier
as an array ofUInt8
values with ASN.1 format.Declaration
Swift
internal func encode() -> [UInt8]
Return Value
An array of
UInt8
values representing the ASN1 format encoded OID. -
Encodes the
ObjectIdentifier
as an array ofUInt8
values with a custom tag in ASN.1 format.Declaration
Swift
internal func encode(withTag tag: UInt64) -> [UInt8]
Parameters
tag
The custom tag value to use in the encoding.
Return Value
An array of
UInt8
values representing the ASN.1 format encoded OID with the specified custom tag. -
Concatenates two
ObjectIdentifier
instances to create a newObjectIdentifier
.Declaration
Swift
static func + (rhs: ObjectIdentifier, lhs: ObjectIdentifier) -> ObjectIdentifier
Parameters
rhs
The right-hand side
ObjectIdentifier
to concatenate.lhs
The left-hand side
ObjectIdentifier
to concatenate.Return Value
A new
ObjectIdentifier
created by concatenatingrhs
andlhs
. -
Checks if the current
ObjectIdentifier
starts with anotherObjectIdentifier
, indicating a prefix relationship between them.Declaration
Swift
func starts(with other: ObjectIdentifier) -> Bool
Parameters
other
The
ObjectIdentifier
to check as a prefix.Return Value
true
if the currentObjectIdentifier
starts withother
; otherwise,false
. -
Removes the first
length
elements from the beginning of the data array.This method modifies the underlying data array by removing the specified number of elements from the beginning.
Note
If thelength
parameter is greater than or equal to the size of the data array, the data array will be emptied.Declaration
Swift
mutating func removeFirst(_ length: Int)
Parameters
length
The number of elements to remove from the beginning of the data array.
-
A human-readable string representation of the
ObjectIdentifier
, joining itsUInt8
values with periods.Declaration
Swift
var description: String { get }
-
Declaration
Swift
typealias StringLiteralType = String
-
Declaration
Swift
var rawValue: String { get }
-
Initializes an
ObjectIdentifier
with a string literal.This initializer splits the input string into its components, which are then converted to
UInt8
values. The resulting array ofUInt8
values is used to represent the object identifier.Note
The input string should follow the dot notation for object identifiers.Warning
If the input string cannot be parsed as a valid object identifier, a runtime error will occur.Declaration
Swift
init(stringLiteral value: String)
Parameters
value
A string representing the object identifier in dot notation (e.g., “1.2.3”).
-
Compares two
ObjectIdentifier
instances for equality based on their underlyingUInt8
data.Declaration
Swift
static func == (rhs: ObjectIdentifier, lhs: ObjectIdentifier) -> Bool
Parameters
rhs
The right-hand side
ObjectIdentifier
to compare.lhs
The left-hand side
ObjectIdentifier
to compare.Return Value
true
if theUInt8
data ofrhs
andlhs
is equal; otherwise,false
.