Class: PqcAsn1::DER::EncryptedKeyInfo
- Inherits:
-
Object
- Object
- PqcAsn1::DER::EncryptedKeyInfo
- Defined in:
- lib/pqc_asn1.rb
Overview
Result returned by parse_encrypted_pkcs8.
An immutable value object holding the two opaque fields of an EncryptedPrivateKeyInfo (RFC 5958) structure. This gem is a codec — it does not perform the actual encryption or decryption. Callers are responsible for:
1. Encrypting a PKCS#8 DER blob (e.g. via OpenSSL or libsodium)
and providing +encryption_algorithm_der+ + +encrypted_data+ to
{DER.build_encrypted_pkcs8}.
2. Decrypting +encrypted_data+ (using +encryption_algorithm+ as a
hint for algorithm + parameters) and passing the result to
{DER.parse_pkcs8}.
Instance Attribute Summary collapse
-
#encrypted_data ⇒ String
readonly
Raw ciphertext bytes (frozen ASCII-8BIT).
-
#encryption_algorithm ⇒ String
readonly
Full AlgorithmIdentifier DER TLV (frozen ASCII-8BIT).
-
#format ⇒ Symbol
readonly
Always
:encrypted_pkcs8.
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
-
#deconstruct_keys(keys) ⇒ Hash{Symbol => Object}
Pattern-matching support (Ruby 2.7+).
- #hash ⇒ Integer
-
#initialize(encryption_algorithm, encrypted_data) ⇒ EncryptedKeyInfo
constructor
A new instance of EncryptedKeyInfo.
- #inspect ⇒ String
-
#to_der ⇒ String
Re-encode to EncryptedPrivateKeyInfo DER.
- #to_h ⇒ Hash{Symbol => Object}
-
#to_pem ⇒ String
Re-encode to PEM with label "ENCRYPTED PRIVATE KEY".
Constructor Details
#initialize(encryption_algorithm, encrypted_data) ⇒ EncryptedKeyInfo
Returns a new instance of EncryptedKeyInfo.
456 457 458 459 460 461 |
# File 'lib/pqc_asn1.rb', line 456 def initialize(encryption_algorithm, encrypted_data) @encryption_algorithm = encryption_algorithm @encrypted_data = encrypted_data @format = :encrypted_pkcs8 freeze end |
Instance Attribute Details
#encrypted_data ⇒ String (readonly)
Returns raw ciphertext bytes (frozen ASCII-8BIT). These are the contents of the encryptedData OCTET STRING; the outer OCTET STRING TLV is stripped.
450 451 452 |
# File 'lib/pqc_asn1.rb', line 450 def encrypted_data @encrypted_data end |
#encryption_algorithm ⇒ String (readonly)
Returns full AlgorithmIdentifier DER TLV (frozen ASCII-8BIT). The tag, length, OID, and any algorithm parameters are all included so callers can pass this directly to their cipher implementation.
445 446 447 |
# File 'lib/pqc_asn1.rb', line 445 def encryption_algorithm @encryption_algorithm end |
#format ⇒ Symbol (readonly)
Returns always :encrypted_pkcs8.
453 454 455 |
# File 'lib/pqc_asn1.rb', line 453 def format @format end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
499 500 501 502 503 |
# File 'lib/pqc_asn1.rb', line 499 def ==(other) other.is_a?(EncryptedKeyInfo) && @encryption_algorithm == other.encryption_algorithm && @encrypted_data == other.encrypted_data end |
#deconstruct_keys(keys) ⇒ Hash{Symbol => Object}
Pattern-matching support (Ruby 2.7+).
485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/pqc_asn1.rb', line 485 def deconstruct_keys(keys) return to_h if keys.nil? keys.each_with_object({}) do |k, h| case k when :encryption_algorithm then h[:encryption_algorithm] = @encryption_algorithm when :encrypted_data then h[:encrypted_data] = @encrypted_data when :format then h[:format] = @format end end end |
#hash ⇒ Integer
508 509 510 |
# File 'lib/pqc_asn1.rb', line 508 def hash [@encryption_algorithm, @encrypted_data].hash end |
#inspect ⇒ String
513 514 515 516 517 |
# File 'lib/pqc_asn1.rb', line 513 def inspect "#<PqcAsn1::DER::EncryptedKeyInfo " \ "algo=#{@encryption_algorithm.bytesize}B " \ "encrypted=#{@encrypted_data.bytesize}B>" end |
#to_der ⇒ String
Re-encode to EncryptedPrivateKeyInfo DER.
465 466 467 |
# File 'lib/pqc_asn1.rb', line 465 def to_der PqcAsn1::DER.build_encrypted_pkcs8(@encryption_algorithm, @encrypted_data) end |
#to_h ⇒ Hash{Symbol => Object}
476 477 478 479 480 |
# File 'lib/pqc_asn1.rb', line 476 def to_h {encryption_algorithm: @encryption_algorithm, encrypted_data: @encrypted_data, format: @format} end |