Class: PqcAsn1::PEM::DecodeResult
- Inherits:
-
Object
- Object
- PqcAsn1::PEM::DecodeResult
- Defined in:
- lib/pqc_asn1.rb
Instance Attribute Summary collapse
-
#data ⇒ String
readonly
Decoded DER bytes (ASCII-8BIT, frozen).
-
#label ⇒ String
readonly
PEM label string (US-ASCII, frozen).
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
-
#deconstruct_keys(keys) ⇒ Hash{Symbol => String}
Pattern-matching support (Ruby 2.7+).
- #hash ⇒ Integer
-
#initialize(data, label) ⇒ DecodeResult
constructor
A new instance of DecodeResult.
- #inspect ⇒ String
-
#to_a ⇒ Array(String, String)
Explicit Array conversion:
data, label = PEM.decode_auto(pem).to_a. - #to_h ⇒ Hash{Symbol => String}
Constructor Details
#initialize(data, label) ⇒ DecodeResult
Returns a new instance of DecodeResult.
591 592 593 594 595 |
# File 'lib/pqc_asn1.rb', line 591 def initialize(data, label) @data = data @label = label freeze end |
Instance Attribute Details
#data ⇒ String (readonly)
Returns decoded DER bytes (ASCII-8BIT, frozen).
585 586 587 |
# File 'lib/pqc_asn1.rb', line 585 def data @data end |
#label ⇒ String (readonly)
Returns PEM label string (US-ASCII, frozen).
588 589 590 |
# File 'lib/pqc_asn1.rb', line 588 def label @label end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
625 626 627 628 629 |
# File 'lib/pqc_asn1.rb', line 625 def ==(other) other.is_a?(DecodeResult) && @data == other.data && @label == other.label end |
#deconstruct_keys(keys) ⇒ Hash{Symbol => String}
Pattern-matching support (Ruby 2.7+).
When keys is non-nil, only the requested keys are returned.
612 613 614 615 616 617 618 619 620 621 |
# File 'lib/pqc_asn1.rb', line 612 def deconstruct_keys(keys) return to_h if keys.nil? keys.each_with_object({}) do |k, h| case k when :data then h[:data] = @data when :label then h[:label] = @label end end end |
#hash ⇒ Integer
634 635 636 |
# File 'lib/pqc_asn1.rb', line 634 def hash [@data, @label].hash end |
#inspect ⇒ String
639 640 641 |
# File 'lib/pqc_asn1.rb', line 639 def inspect "#<PqcAsn1::PEM::DecodeResult label=#{@label.inspect} data=#{@data.bytesize}B>" end |
#to_a ⇒ Array(String, String)
Explicit Array conversion: data, label = PEM.decode_auto(pem).to_a
599 600 601 |
# File 'lib/pqc_asn1.rb', line 599 def to_a [@data, @label] end |
#to_h ⇒ Hash{Symbol => String}
604 605 606 |
# File 'lib/pqc_asn1.rb', line 604 def to_h {data: @data, label: @label} end |