Class: Saro::Dat::DatCertificate

Inherits:
Object
  • Object
show all
Defined in:
lib/saro/dat/dat_certificate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cid, signature_key, crypto_key, dat_issue_begin, dat_issue_end, dat_ttl) ⇒ 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, signature_key, crypto_key, dat_issue_begin, dat_issue_end, dat_ttl)
  @cid = cid
  @signature_key = signature_key
  @crypto_key = crypto_key
  @dat_issue_begin = dat_issue_begin
  @dat_issue_end = dat_issue_end
  @dat_ttl = dat_ttl
end

Instance Attribute Details

#cidObject (readonly)

Returns the value of attribute cid.



10
11
12
# File 'lib/saro/dat/dat_certificate.rb', line 10

def cid
  @cid
end

#crypto_keyObject (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_beginObject (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_endObject (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_ttlObject (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_keyObject (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

.imports(format_str) ⇒ Object

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/saro/dat/dat_certificate.rb', line 31

def self.imports(format_str)
  split = format_str.split(".")
  raise ArgumentError, "Invalid Certificate format" if split.length != 8

  cid = split[0].to_i(16)
  sig_key = Saro::Dat::DatSignatureKey.imports(split[1], split[2])
  cry_key = Saro::Dat::DatCryptoKey.imports(split[3], Saro::Dat::Util.decode_base64_url(split[4]))

  new(
    cid, sig_key, cry_key,
    split[5].to_i, split[6].to_i, split[7].to_i
  )
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/saro/dat/dat_certificate.rb', line 50

def expired?
  Time.now.to_i > (@dat_issue_end + @dat_ttl)
end

#exports(option) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/saro/dat/dat_certificate.rb', line 21

def exports(option)
  cid_hex = @cid.to_s(16)
  sig_alg = @signature_key.algorithm
  sig_key = @signature_key.exports(option)
  cry_alg = @crypto_key.algorithm
  cry_key = Saro::Dat::Util.encode_base64_url_str(@crypto_key.exports)

  "#{cid_hex}.#{sig_alg}.#{sig_key}.#{cry_alg}.#{cry_key}.#{@dat_issue_begin}.#{@dat_issue_end}.#{@dat_ttl}"
end

#has_signing_key?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/saro/dat/dat_certificate.rb', line 54

def has_signing_key?
  @signature_key.has_signing_key?
end

#issuable?Boolean

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/saro/dat/dat_certificate.rb', line 45

def issuable?
  now = Time.now.to_i
  has_signing_key? && @dat_issue_begin <= now && now <= @dat_issue_end
end