Class: PqcAsn1::DER::Cursor
- Inherits:
-
Object
- Object
- PqcAsn1::DER::Cursor
- Defined in:
- lib/pqc_asn1.rb
Overview
Zero-copy DER reader for callers that need fine-grained traversal beyond parse_spki / parse_pkcs8.
Advanced API — most callers should use the high-level methods (parse_spki, parse_pkcs8, parse_encrypted_pkcs8) instead. Use Cursor only when you need to navigate a custom DER structure that the built-in parsers do not cover.
A Cursor wraps a binary String and provides sequential read operations that advance an internal position without copying data. #read_sequence returns a new Cursor scoped to the SEQUENCE content, sharing the same source — still zero-copy.
All read_* methods return frozen ASCII-8BIT Strings. The Cursor
holds a strong reference to the source String, preventing GC while
any sub-cursor is alive.
Defined by the C extension (ext/pqc_asn1/cursor.c).
Instance Method Summary collapse
-
#data ⇒ String
Return the full backing data of this cursor (or the relevant substring for a sub-cursor).
-
#eof? ⇒ Boolean
True if all bytes have been consumed.
-
#initialize(data, pos = 0) ⇒ Cursor
constructor
Create a new Cursor over DER-encoded data.
-
#peek_tag ⇒ Integer?
Return the tag byte at the current position without advancing.
-
#pos ⇒ Integer
Current byte offset within the source.
-
#read(expected_tag) ⇒ String
Read the content bytes of the next TLV with the given tag.
-
#read_bit_string ⇒ String
Shorthand for
read(0x03). -
#read_integer ⇒ String
Shorthand for
read(0x02). -
#read_octet_string ⇒ String
Shorthand for
read(0x04). -
#read_oid ⇒ String
Shorthand for
read(0x06). -
#read_optional(expected_tag) ⇒ String?
Like #read but returns
nil(without advancing) if at EOF or the next tag does not match. -
#read_raw(expected_tag) ⇒ String
Read the full TLV bytes (tag + length + value) at the current position.
-
#read_raw_optional(expected_tag) ⇒ String?
Like #read_raw but returns
nilif at EOF or tag mismatch. -
#read_sequence ⇒ Cursor
Read a SEQUENCE (tag 0x30) and return a new Cursor scoped to its content.
-
#remaining ⇒ Integer
Number of unconsumed bytes.
-
#skip(expected_tag) ⇒ self
Skip the next TLV with the given tag.
-
#skip_optional(expected_tag) ⇒ self?
Like #skip but returns
nilif at EOF or tag mismatch.
Constructor Details
Instance Method Details
#data ⇒ String
Return the full backing data of this cursor (or the relevant substring for a sub-cursor). Frozen ASCII-8BIT String.
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |
#eof? ⇒ Boolean
Returns true if all bytes have been consumed.
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |
#peek_tag ⇒ Integer?
Return the tag byte at the current position without advancing.
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |
#pos ⇒ Integer
Returns current byte offset within the source.
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |
#read(expected_tag) ⇒ String
Read the content bytes of the next TLV with the given tag. Advances the cursor past the entire TLV.
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |
#read_bit_string ⇒ String
Shorthand for read(0x03).
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |
#read_integer ⇒ String
Shorthand for read(0x02).
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |
#read_octet_string ⇒ String
Shorthand for read(0x04).
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |
#read_oid ⇒ String
Shorthand for read(0x06).
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |
#read_optional(expected_tag) ⇒ String?
Like #read but returns nil (without advancing) if at EOF or
the next tag does not match.
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |
#read_raw(expected_tag) ⇒ String
Read the full TLV bytes (tag + length + value) at the current position. Useful for forwarding an opaque field without interpreting it.
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |
#read_raw_optional(expected_tag) ⇒ String?
Like #read_raw but returns nil if at EOF or tag mismatch.
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |
#read_sequence ⇒ Cursor
Read a SEQUENCE (tag 0x30) and return a new Cursor scoped to its content. The sub-cursor shares the same source String (zero-copy).
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |
#remaining ⇒ Integer
Returns number of unconsumed bytes.
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |
#skip(expected_tag) ⇒ self
Skip the next TLV with the given tag. Returns self for chaining.
241 |
# File 'lib/pqc_asn1.rb', line 241 class Cursor; end |