Class: AppIdentity::Internal
- Inherits:
-
Object
- Object
- AppIdentity::Internal
- Includes:
- Validation
- Defined in:
- lib/app_identity/internal.rb
Overview
:nodoc:
Class Method Summary collapse
- .generate_proof!(app, **kwargs) ⇒ Object
- .instance ⇒ Object
- .parse_proof!(proof) ⇒ Object
- .verify_proof!(proof, app, **kwargs) ⇒ Object
Instance Method Summary collapse
- #generate_proof!(app, nonce: nil, version: nil, disallowed: nil) ⇒ Object
- #parse_proof!(proof) ⇒ Object
- #verify_proof!(proof, app, disallowed: nil) ⇒ Object
Methods included from Validation
#validate_config, #validate_id, #validate_padlock, #validate_secret, #validate_version
Class Method Details
.generate_proof!(app, **kwargs) ⇒ Object
17 18 19 |
# File 'lib/app_identity/internal.rb', line 17 def generate_proof!(app, **kwargs) instance.generate_proof!(app, **kwargs) end |
.instance ⇒ Object
13 14 15 |
# File 'lib/app_identity/internal.rb', line 13 def instance @instance ||= new end |
.parse_proof!(proof) ⇒ Object
21 22 23 |
# File 'lib/app_identity/internal.rb', line 21 def parse_proof!(proof) instance.parse_proof!(proof) end |
.verify_proof!(proof, app, **kwargs) ⇒ Object
25 26 27 |
# File 'lib/app_identity/internal.rb', line 25 def verify_proof!(proof, app, **kwargs) instance.verify_proof!(proof, app, **kwargs) end |
Instance Method Details
#generate_proof!(app, nonce: nil, version: nil, disallowed: nil) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/app_identity/internal.rb', line 30 def generate_proof!(app, nonce: nil, version: nil, disallowed: nil) app = AppIdentity::App.new(app) version ||= app.version nonce ||= app.generate_nonce(version) __generate_proof(app, nonce, version, disallowed: disallowed) end |
#parse_proof!(proof) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/app_identity/internal.rb', line 38 def parse_proof!(proof) return proof if proof.is_a?(Hash) raise AppIdentity::Error, "proof must be a string or a map" unless proof.is_a?(String) parts = Base64.decode64(proof).split(":", -1) case parts.length when 4 version, id, nonce, padlock = parts version = validate_version(version) AppIdentity::Versions.allowed!(version) {version: version, id: id, nonce: nonce, padlock: padlock} when 3 id, nonce, padlock = parts {version: 1, id: id, nonce: nonce, padlock: padlock} else raise AppIdentity::Error, "proof must have 3 parts (version 1) or 4 parts (any version)" end end |
#verify_proof!(proof, app, disallowed: nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/app_identity/internal.rb', line 62 def verify_proof!(proof, app, disallowed: nil) proof = parse_proof!(proof) app = app.call(proof) if app.respond_to?(:call) app = AppIdentity::App.new(app) raise AppIdentity::Error, "proof and app do not match" unless app.id == proof[:id] raise AppIdentity::Error, "proof and app version mismatch" if app.version > proof[:version] AppIdentity::Versions.allowed!(proof[:version], disallowed) valid_nonce!(proof[:nonce], proof[:version], app.config) validate_padlock(proof[:padlock]) padlock = __generate_padlock(app, proof[:nonce], proof[:version]) compare_padlocks(padlock, proof[:padlock]) ? app.verify : nil end |