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_issuance_end_seconds ⇒ Object
readonly
Returns the value of attribute dat_issuance_end_seconds.
-
#dat_issuance_start_seconds ⇒ Object
readonly
Returns the value of attribute dat_issuance_start_seconds.
-
#dat_ttl_seconds ⇒ Object
readonly
Returns the value of attribute dat_ttl_seconds.
-
#signature_key ⇒ Object
readonly
Returns the value of attribute signature_key.
Class Method Summary collapse
- .generate(cid, dat_issuance_start_seconds, dat_issuance_duration_seconds, dat_ttl_seconds, signature_algorithm, crypto_algorithm) ⇒ Object
- .imports(format_str) ⇒ Object
Instance Method Summary collapse
- #expired ⇒ Object (also: #expired?)
- #exports(verify_only = false) ⇒ Object
-
#initialize(cid, dat_issuance_start_seconds, dat_issuance_duration_seconds, dat_ttl_seconds, signature_key, crypto_key) ⇒ DatCertificate
constructor
A new instance of DatCertificate.
- #issuable ⇒ Object (also: #issuable?)
- #pair ⇒ Object (also: #pair?)
- #signable ⇒ Object (also: #signable?)
- #support_verify_only ⇒ Object
Constructor Details
#initialize(cid, dat_issuance_start_seconds, dat_issuance_duration_seconds, dat_ttl_seconds, 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, dat_issuance_start_seconds, dat_issuance_duration_seconds, dat_ttl_seconds, signature_key, crypto_key) @cid = cid @dat_issuance_start_seconds = dat_issuance_start_seconds @dat_issuance_end_seconds = dat_issuance_start_seconds + dat_issuance_duration_seconds @dat_ttl_seconds = dat_ttl_seconds @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_issuance_end_seconds ⇒ Object (readonly)
Returns the value of attribute dat_issuance_end_seconds.
10 11 12 |
# File 'lib/saro/dat/dat_certificate.rb', line 10 def dat_issuance_end_seconds @dat_issuance_end_seconds end |
#dat_issuance_start_seconds ⇒ Object (readonly)
Returns the value of attribute dat_issuance_start_seconds.
10 11 12 |
# File 'lib/saro/dat/dat_certificate.rb', line 10 def dat_issuance_start_seconds @dat_issuance_start_seconds end |
#dat_ttl_seconds ⇒ Object (readonly)
Returns the value of attribute dat_ttl_seconds.
10 11 12 |
# File 'lib/saro/dat/dat_certificate.rb', line 10 def dat_ttl_seconds @dat_ttl_seconds 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, dat_issuance_start_seconds, dat_issuance_duration_seconds, dat_ttl_seconds, 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, dat_issuance_start_seconds, dat_issuance_duration_seconds, dat_ttl_seconds, signature_algorithm, crypto_algorithm) new( cid, dat_issuance_start_seconds, dat_issuance_duration_seconds, dat_ttl_seconds, 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) dat_issuance_start_seconds = parts[1].to_i dat_issuance_duration_seconds = parts[2].to_i dat_ttl_seconds = parts[3].to_i signature_algorithm = parts[4] crypto_algorithm = parts[5] signature_key = Saro::Dat::DatSignature.imports(signature_algorithm, parts[6]) crypto_key = Saro::Dat::DatCrypto.imports(crypto_algorithm, parts[7]) new(cid, dat_issuance_start_seconds, dat_issuance_duration_seconds, dat_ttl_seconds, 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_issuance_end_seconds + @dat_ttl_seconds) 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) dat_issuance_start_seconds = @dat_issuance_start_seconds.to_s dat_issuance_duration_seconds = (@dat_issuance_end_seconds - @dat_issuance_start_seconds).to_s dat_ttl_seconds = @dat_ttl_seconds.to_s signature_algorithm = @signature_key.algorithm crypto_algorithm = @crypto_key.algorithm signature_key = @signature_key.exports(verify_only) crypto_key = @crypto_key.exports "#{cid_hex}.#{dat_issuance_start_seconds}.#{dat_issuance_duration_seconds}.#{dat_ttl_seconds}.#{signature_algorithm}.#{crypto_algorithm}.#{signature_key}.#{crypto_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_issuance_start_seconds <= now && now <= @dat_issuance_end_seconds 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 |
#support_verify_only ⇒ Object
75 76 77 |
# File 'lib/saro/dat/dat_certificate.rb', line 75 def support_verify_only @signature_key.support_verify_only end |