Class: PqcAsn1::PEM::DecodeResult

Inherits:
Object
  • Object
show all
Defined in:
lib/pqc_asn1.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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).

Returns:

  • (String) —

    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).

Returns:

  • (String) —

    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?

Parameters:

  • other (Object)

Returns:

  • (Boolean)


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.

Parameters:

  • keys (Array<Symbol>, nil)

Returns:

  • (Hash{Symbol => String})


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

Returns:

  • (Integer)


634
635
636
# File 'lib/pqc_asn1.rb', line 634

def hash
  [@data, @label].hash
end

#inspect ⇒ String

Returns:

  • (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

Returns:

  • (Array(String, String))


599
600
601
# File 'lib/pqc_asn1.rb', line 599

def to_a
  [@data, @label]
end

#to_h ⇒ Hash{Symbol => String}

Returns:

  • (Hash{Symbol => String})


604
605
606
# File 'lib/pqc_asn1.rb', line 604

def to_h
  {data: @data, label: @label}
end