Class: JOSE::JWE::ENC_XC20P

Inherits:
Struct
  • Object
show all
Defined in:
lib/jose/jwe/enc_xc20p.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bitsObject

Returns the value of attribute bits

Returns:

  • (Object)

    the current value of bits



1
2
3
# File 'lib/jose/jwe/enc_xc20p.rb', line 1

def bits
  @bits
end

#cek_lenObject

Returns the value of attribute cek_len

Returns:

  • (Object)

    the current value of cek_len



1
2
3
# File 'lib/jose/jwe/enc_xc20p.rb', line 1

def cek_len
  @cek_len
end

#cipher_nameObject

Returns the value of attribute cipher_name

Returns:

  • (Object)

    the current value of cipher_name



1
2
3
# File 'lib/jose/jwe/enc_xc20p.rb', line 1

def cipher_name
  @cipher_name
end

#iv_lenObject

Returns the value of attribute iv_len

Returns:

  • (Object)

    the current value of 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

#algorithmObject

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_cekObject



41
42
43
# File 'lib/jose/jwe/enc_xc20p.rb', line 41

def next_cek
  return SecureRandom.random_bytes(cek_len)
end

#next_ivObject



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