Module: JOSE

Defined in:
lib/jose.rb,
lib/jose/jwa.rb,
lib/jose/jwe.rb,
lib/jose/jwk.rb,
lib/jose/jws.rb,
lib/jose/jwt.rb,
lib/jose/version.rb

Overview

JOSE stands for JSON Object Signing and Encryption which is a is a set of standards established by the JOSE Working Group.

JOSE is split into 5 main components:

Additional specifications and drafts implemented:

Defined Under Namespace

Modules: JWA Classes: EncryptedBinary, EncryptedMap, JWE, JWK, JWS, JWT, Map, SignedBinary, SignedMap

Constant Summary collapse

VERSION =
"1.2.0"

Class Method Summary collapse

Class Method Details

.crypto_fallbackBoolean

Gets the current Cryptographic Algorithm Fallback state, defaults to false.

Returns:

  • (Boolean)


39
40
41
# File 'lib/jose.rb', line 39

def self.crypto_fallback
  return @__crypto_fallback__
end

.crypto_fallback=(boolean) ⇒ Boolean

Sets the current Cryptographic Algorithm Fallback state.

Parameters:

  • boolean (Boolean)

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
# File 'lib/jose.rb', line 46

def self.crypto_fallback=(boolean)
  boolean = !!boolean
  MUTEX.synchronize {
    @__crypto_fallback__ = boolean
    __config_change__
  }
  return boolean
end

.curve25519_moduleModule

Gets the current Curve25519 module used by JOSE::JWA::Curve25519, see curve25519_module= for default.

Returns:

  • (Module)


57
58
59
# File 'lib/jose.rb', line 57

def self.curve25519_module
  return JOSE::JWA::Curve25519.__implementation__
end

.curve25519_module=(mod) ⇒ Module

Sets the current Curve25519 module used by JOSE::JWA::Curve25519.

Currently supported Curve25519 modules (first found is used as default):

Additional modules that implement the functions specified in JOSE::JWA::Curve25519 may also be used.

Parameters:

  • mod (Module)

Returns:

  • (Module)


71
72
73
# File 'lib/jose.rb', line 71

def self.curve25519_module=(mod)
  JOSE::JWA::Curve25519.__implementation__ = mod
end

.curve448_moduleModule

Gets the current Curve448 module used by JOSE::JWA::Curve448, see curve25519_module= for default.

Returns:

  • (Module)


77
78
79
# File 'lib/jose.rb', line 77

def self.curve448_module
  return JOSE::JWA::Curve448.__implementation__
end

.curve448_module=(mod) ⇒ Module

Sets the current Curve448 module used by JOSE::JWA::Curve448.

Currently supported Curve448 modules (first found is used as default):

Additional modules that implement the functions specified in JOSE::JWA::Curve448 may also be used.

Parameters:

  • mod (Module)

Returns:

  • (Module)


90
91
92
# File 'lib/jose.rb', line 90

def self.curve448_module=(mod)
  JOSE::JWA::Curve448.__implementation__ = mod
end

.decode(binary) ⇒ Object

Decode JSON binary to a term.

Parameters:

  • binary (String)

Returns:

  • (Object)


97
98
99
# File 'lib/jose.rb', line 97

def self.decode(binary)
  return JSON.load(binary)
end

.encode(term) ⇒ Object

Encode a term to JSON binary and sorts Hash and JOSE::Map keys.

Parameters:

  • term (Object)

Returns:

  • (Object)


104
105
106
# File 'lib/jose.rb', line 104

def self.encode(term)
  return JSON.dump(sort_maps(term))
end

.unsecured_signingBoolean

Gets the current Unsecured Signing state, defaults to false.

Returns:

  • (Boolean)


110
111
112
# File 'lib/jose.rb', line 110

def self.unsecured_signing
  return @__unsecured_signing__
end

.unsecured_signing=(boolean) ⇒ Boolean

Sets the current Unsecured Signing state.

Enables/disables the "none" algorithm used for signing and verifying.

See Critical vulnerabilities in JSON Web Token libraries for more information.

Parameters:

  • boolean (Boolean)

Returns:

  • (Boolean)


121
122
123
124
125
126
127
128
# File 'lib/jose.rb', line 121

def self.unsecured_signing=(boolean)
  boolean = !!boolean
  MUTEX.synchronize {
    @__unsecured_signing__ = boolean
    __config_change__
  }
  return boolean
end

.urlsafe_decode64(binary) ⇒ String

Returns the Base64Url decoded version of binary without padding.

Parameters:

  • binary (String)

Returns:

  • (String)


133
134
135
136
137
138
139
140
141
142
# File 'lib/jose.rb', line 133

def self.urlsafe_decode64(binary)
  binary = binary.tr('-_', '+/')
  case binary.bytesize % 4
  when 2
    binary += '=='
  when 3
    binary += '='
  end
  return Base64.decode64(binary)
end

.urlsafe_encode64(binary) ⇒ String

Returns the Base64Url encoded version of binary without padding.

Parameters:

  • binary (String)

Returns:

  • (String)


147
148
149
# File 'lib/jose.rb', line 147

def self.urlsafe_encode64(binary)
  return Base64.strict_encode64(binary).tr('+/', '-_').delete('=')
end

.xchacha20poly1305_moduleModule

Gets the current XChaCha20-Poly1305 module used by JOSE::JWA::XChaCha20Poly1305, see xchacha20poly1305_module= for default.

Returns:

  • (Module)


153
154
155
# File 'lib/jose.rb', line 153

def self.xchacha20poly1305_module
  return JOSE::JWA::XChaCha20Poly1305.__implementation__
end

.xchacha20poly1305_module=(mod) ⇒ Module

Sets the current XChaCha20Poly1305 module used by JOSE::JWA::XChaCha20Poly1305.

Currently supported XChaCha20Poly1305 modules (first found is used as default):

Additional modules that implement the functions specified in JOSE::JWA::XChaCha20Poly1305 may also be used.

Parameters:

  • mod (Module)

Returns:

  • (Module)


166
167
168
# File 'lib/jose.rb', line 166

def self.xchacha20poly1305_module=(mod)
  JOSE::JWA::XChaCha20Poly1305.__implementation__ = mod
end