Class: JOSE::JWE::ENC_XC20P
- Inherits:
-
Struct
- Object
- Struct
- JOSE::JWE::ENC_XC20P
- Defined in:
- lib/jose/jwe/enc_xc20p.rb
Instance Attribute Summary collapse
-
#bits ⇒ Object
Returns the value of attribute bits.
-
#cek_len ⇒ Object
Returns the value of attribute cek_len.
-
#cipher_name ⇒ Object
Returns the value of attribute cipher_name.
-
#iv_len ⇒ Object
Returns the value of attribute iv_len.
Class Method Summary collapse
-
.from_map(fields) ⇒ Object
JOSE::JWE callbacks.
Instance Method Summary collapse
-
#algorithm ⇒ Object
JOSE::JWE::ENC callbacks.
- #block_decrypt(aad_cipher_text_cipher_tag, cek, iv) ⇒ Object
- #block_encrypt(aad_plain_text, cek, iv) ⇒ Object
- #next_cek ⇒ Object
- #next_iv ⇒ Object
- #to_map(fields) ⇒ Object
Instance Attribute Details
#bits ⇒ Object
Returns the value of attribute bits
1 2 3 |
# File 'lib/jose/jwe/enc_xc20p.rb', line 1 def bits @bits end |
#cek_len ⇒ Object
Returns the value of attribute cek_len
1 2 3 |
# File 'lib/jose/jwe/enc_xc20p.rb', line 1 def cek_len @cek_len end |
#cipher_name ⇒ Object
Returns the value of attribute cipher_name
1 2 3 |
# File 'lib/jose/jwe/enc_xc20p.rb', line 1 def cipher_name @cipher_name end |
#iv_len ⇒ Object
Returns the value of attribute iv_len
1 2 3 |
# File 'lib/jose/jwe/enc_xc20p.rb', line 1 def iv_len @iv_len end |
Class Method Details
.from_map(fields) ⇒ Object
JOSE::JWE callbacks
5 6 7 8 9 10 11 12 |
# File 'lib/jose/jwe/enc_xc20p.rb', line 5 def self.from_map(fields) case fields['enc'] when 'XC20P' return new('xchacha20-poly1305', 256, 32, 24), fields.delete('enc') else raise ArgumentError, "invalid 'enc' for JWE: #{fields['enc'].inspect}" end end |
Instance Method Details
#algorithm ⇒ Object
JOSE::JWE::ENC callbacks
20 21 22 23 24 25 26 27 |
# File 'lib/jose/jwe/enc_xc20p.rb', line 20 def algorithm case cipher_name when 'xchacha20-poly1305' return 'XC20P' else raise ArgumentError, "unhandled JOSE::JWE::ENC_XC20P cipher name: #{cipher_name.inspect}" end end |
#block_decrypt(aad_cipher_text_cipher_tag, cek, iv) ⇒ Object
29 30 31 32 33 |
# File 'lib/jose/jwe/enc_xc20p.rb', line 29 def block_decrypt(aad_cipher_text_cipher_tag, cek, iv) aad, cipher_text, cipher_tag = aad_cipher_text_cipher_tag plain_text = JOSE.xchacha20poly1305_module().xchacha20poly1305_aead_decrypt(cek, iv, aad, cipher_text, cipher_tag) return plain_text end |
#block_encrypt(aad_plain_text, cek, iv) ⇒ Object
35 36 37 38 39 |
# File 'lib/jose/jwe/enc_xc20p.rb', line 35 def block_encrypt(aad_plain_text, cek, iv) aad, plain_text = aad_plain_text cipher_text, cipher_tag = JOSE.xchacha20poly1305_module().xchacha20poly1305_aead_encrypt(cek, iv, aad, plain_text) return cipher_text, cipher_tag end |
#next_cek ⇒ Object
41 42 43 |
# File 'lib/jose/jwe/enc_xc20p.rb', line 41 def next_cek return SecureRandom.random_bytes(cek_len) end |
#next_iv ⇒ Object
45 46 47 |
# File 'lib/jose/jwe/enc_xc20p.rb', line 45 def next_iv return SecureRandom.random_bytes(iv_len) end |
#to_map(fields) ⇒ Object
14 15 16 |
# File 'lib/jose/jwe/enc_xc20p.rb', line 14 def to_map(fields) return fields.put('enc', algorithm) end |