Exception: PqcAsn1::Error
- Inherits:
-
StandardError
- Object
- StandardError
- PqcAsn1::Error
- Defined in:
- lib/pqc_asn1.rb
Overview
Base error class for all PqcAsn1 errors.
Two attributes enable programmatic error handling without parsing the message string:
code — fine-grained symbol matching the C library status code:
:outer_sequence, :version, :algorithm, :key, :unused_bits,
:trailing_data, :pem_no_markers, :pem_label, :base64,
:invalid_oid, :extra_fields, :overflow, :alloc,
:buffer_too_small, :label_too_long, :der_parse,
:null_param, :pem_malformed
category — coarse bucket derived from code:
:malformed_input — a DER field is structurally wrong
:malformed_encoding — Base64 / PEM boundary / label problem
:validation — caller-side constraint violation (bad OID, overflow, etc.)
:system — memory allocation failed
rescue PqcAsn1::ParseError => e
case e.category
when ParseError::MALFORMED_INPUT then retry_with_lenient_parser
when ParseError::MALFORMED_ENCODING then raise "check your PEM"
end
end
Direct Known Subclasses
Instance Attribute Summary collapse
-
#code ⇒ Symbol?
readonly
Fine-grained machine-readable error code.
-
#offset ⇒ Integer?
readonly
Byte offset in the input where the error was detected, or nil when the error is not parse-position-specific.
Instance Method Summary collapse
-
#category ⇒ Symbol?
Coarse error category derived from
code: :malformed_input, :malformed_encoding, :validation, or :system. -
#initialize(msg = nil, code: nil, offset: nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(msg = nil, code: nil, offset: nil) ⇒ Error
Returns a new instance of Error.
54 55 56 57 58 |
# File 'lib/pqc_asn1.rb', line 54 def initialize(msg = nil, code: nil, offset: nil) @code = code @offset = offset super(msg) end |
Instance Attribute Details
#code ⇒ Symbol? (readonly)
Returns fine-grained machine-readable error code.
44 45 46 |
# File 'lib/pqc_asn1.rb', line 44 def code @code end |
#offset ⇒ Integer? (readonly)
Returns byte offset in the input where the error was detected, or nil when the error is not parse-position-specific. Set by the C extension for Cursor and DER parse errors.
49 50 51 |
# File 'lib/pqc_asn1.rb', line 49 def offset @offset end |
Instance Method Details
#category ⇒ Symbol?
Coarse error category derived from code:
:malformed_input, :malformed_encoding, :validation, or :system.
Returns nil when code is nil or not categorised.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pqc_asn1.rb', line 63 def category case @code when :outer_sequence, :version, :algorithm, :key, :unused_bits, :trailing_data, :extra_fields, :der_parse :malformed_input when :pem_no_markers, :pem_label, :base64, :pem_malformed :malformed_encoding when :invalid_oid, :overflow, :buffer_too_small, :label_too_long, :null_param :validation when :alloc :system end end |