Class: Saro::Dat::DatCertificate
- Inherits:
-
Object
- Object
- Saro::Dat::DatCertificate
- Defined in:
- lib/saro/dat/dat_certificate.rb
Instance Attribute Summary collapse
-
#cid ⇒ Object
readonly
Returns the value of attribute cid.
-
#crypto_key ⇒ Object
readonly
Returns the value of attribute crypto_key.
-
#dat_issue_begin ⇒ Object
readonly
Returns the value of attribute dat_issue_begin.
-
#dat_issue_end ⇒ Object
readonly
Returns the value of attribute dat_issue_end.
-
#dat_ttl ⇒ Object
readonly
Returns the value of attribute dat_ttl.
-
#signature_key ⇒ Object
readonly
Returns the value of attribute signature_key.
Class Method Summary collapse
- .generate(cid, issued_at, issuance_duration, dat_ttl, signature_algorithm, crypto_algorithm) ⇒ Object
- .imports(format_str) ⇒ Object
Instance Method Summary collapse
- #expired ⇒ Object (also: #expired?)
- #exports(verify_only = false) ⇒ Object
-
#initialize(cid, issued_at, issuance_duration, dat_ttl, signature_key, crypto_key) ⇒ DatCertificate
constructor
A new instance of DatCertificate.
- #issuable ⇒ Object (also: #issuable?)
- #pair ⇒ Object (also: #pair?)
- #signable ⇒ Object (also: #signable?)
Constructor Details
#initialize(cid, issued_at, issuance_duration, dat_ttl, signature_key, crypto_key) ⇒ DatCertificate
Returns a new instance of DatCertificate.
12 13 14 15 16 17 18 19 |
# File 'lib/saro/dat/dat_certificate.rb', line 12 def initialize(cid, issued_at, issuance_duration, dat_ttl, signature_key, crypto_key) @cid = cid @dat_issue_begin = issued_at @dat_issue_end = issued_at + issuance_duration @dat_ttl = dat_ttl @signature_key = signature_key @crypto_key = crypto_key end |
Instance Attribute Details
#cid ⇒ Object (readonly)
Returns the value of attribute cid.
10 11 12 |
# File 'lib/saro/dat/dat_certificate.rb', line 10 def cid @cid end |
#crypto_key ⇒ Object (readonly)
Returns the value of attribute crypto_key.
10 11 12 |
# File 'lib/saro/dat/dat_certificate.rb', line 10 def crypto_key @crypto_key end |
#dat_issue_begin ⇒ Object (readonly)
Returns the value of attribute dat_issue_begin.
10 11 12 |
# File 'lib/saro/dat/dat_certificate.rb', line 10 def dat_issue_begin @dat_issue_begin end |
#dat_issue_end ⇒ Object (readonly)
Returns the value of attribute dat_issue_end.
10 11 12 |
# File 'lib/saro/dat/dat_certificate.rb', line 10 def dat_issue_end @dat_issue_end end |
#dat_ttl ⇒ Object (readonly)
Returns the value of attribute dat_ttl.
10 11 12 |
# File 'lib/saro/dat/dat_certificate.rb', line 10 def dat_ttl @dat_ttl end |
#signature_key ⇒ Object (readonly)
Returns the value of attribute signature_key.
10 11 12 |
# File 'lib/saro/dat/dat_certificate.rb', line 10 def signature_key @signature_key end |
Class Method Details
.generate(cid, issued_at, issuance_duration, dat_ttl, signature_algorithm, crypto_algorithm) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/saro/dat/dat_certificate.rb', line 34 def self.generate(cid, issued_at, issuance_duration, dat_ttl, signature_algorithm, crypto_algorithm) new( cid, issued_at, issuance_duration, dat_ttl, Saro::Dat::DatSignature.generate(signature_algorithm), Saro::Dat::DatCrypto.generate(crypto_algorithm) ) end |
.imports(format_str) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/saro/dat/dat_certificate.rb', line 42 def self.imports(format_str) parts = format_str.split(".") raise ArgumentError, "Invalid Certificate format" if parts.length != 8 cid = parts[0].to_i(16) issued_at = parts[1].to_i issuance_duration = parts[2].to_i ttl = parts[3].to_i sig_algo = parts[4] cry_algo = parts[5] signature_key = Saro::Dat::DatSignature.imports(sig_algo, parts[6]) crypto_key = Saro::Dat::DatCrypto.imports(cry_algo, parts[7]) new(cid, issued_at, issuance_duration, ttl, signature_key, crypto_key) end |
Instance Method Details
#expired ⇒ Object Also known as: expired?
63 64 65 |
# File 'lib/saro/dat/dat_certificate.rb', line 63 def expired Time.now.to_i > (@dat_issue_end + @dat_ttl) end |
#exports(verify_only = false) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/saro/dat/dat_certificate.rb', line 21 def exports(verify_only = false) cid_hex = @cid.to_s(16) issued_at = @dat_issue_begin.to_s issuance_duration = (@dat_issue_end - @dat_issue_begin).to_s ttl = @dat_ttl.to_s sig_alg = @signature_key.algorithm cry_alg = @crypto_key.algorithm sig_key = @signature_key.exports(verify_only) cry_key = @crypto_key.exports "#{cid_hex}.#{issued_at}.#{issuance_duration}.#{ttl}.#{sig_alg}.#{cry_alg}.#{sig_key}.#{cry_key}" end |
#issuable ⇒ Object Also known as: issuable?
58 59 60 61 |
# File 'lib/saro/dat/dat_certificate.rb', line 58 def issuable now = Time.now.to_i signable && @dat_issue_begin <= now && now <= @dat_issue_end end |
#pair ⇒ Object Also known as: pair?
71 72 73 |
# File 'lib/saro/dat/dat_certificate.rb', line 71 def pair @signature_key.pair end |
#signable ⇒ Object Also known as: signable?
67 68 69 |
# File 'lib/saro/dat/dat_certificate.rb', line 67 def signable @signature_key.signable end |