Module: JOSE

Defined in:
lib/jose.rb,
lib/jose/jws.rb,
lib/jose/jwk.rb,
lib/jose/jwa.rb,
lib/jose/jwe.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 =
"0.3.1"

Class Method Summary collapse

Class Method Details

.crypto_fallbackBoolean

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

Returns:

  • (Boolean)

37
38
39
# File 'lib/jose.rb', line 37

def self.crypto_fallback
  return @__crypto_fallback__
end

.crypto_fallback=(boolean) ⇒ Boolean

Sets the current Cryptographic Algorithm Fallback state.

Parameters:

  • boolean (Boolean)

Returns:

  • (Boolean)

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

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)

55
56
57
# File 'lib/jose.rb', line 55

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)

69
70
71
# File 'lib/jose.rb', line 69

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)

75
76
77
# File 'lib/jose.rb', line 75

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)

88
89
90
# File 'lib/jose.rb', line 88

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)

95
96
97
# File 'lib/jose.rb', line 95

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)

102
103
104
# File 'lib/jose.rb', line 102

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

.unsecured_signingBoolean

Gets the current Unsecured Signing state, defaults to false.

Returns:

  • (Boolean)

108
109
110
# File 'lib/jose.rb', line 108

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)

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

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)

131
132
133
134
135
136
137
138
139
# File 'lib/jose.rb', line 131

def self.urlsafe_decode64(binary)
  case binary.bytesize % 4
  when 2
    binary += '=='
  when 3
    binary += '='
  end
  return Base64.urlsafe_decode64(binary)
end

.urlsafe_encode64(binary) ⇒ String

Returns the Base64Url encoded version of binary without padding.

Parameters:

  • binary (String)

Returns:

  • (String)

144
145
146
# File 'lib/jose.rb', line 144

def self.urlsafe_encode64(binary)
  return Base64.urlsafe_encode64(binary).tr('=', '')
end