Class: IcAgent::Certificate
- Inherits:
-
Object
- Object
- IcAgent::Certificate
- Defined in:
- lib/ic_agent/certificate.rb
Class Method Summary collapse
- .find_label(l, trees) ⇒ Object
- .flatten_forks(t) ⇒ Object
- .lookup(path, cert) ⇒ Object
- .lookup_path(path, tree) ⇒ Object
Class Method Details
.find_label(l, trees) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/ic_agent/certificate.rb', line 45 def self.find_label(l, trees) trees.each do |t| if t[0] == NodeId::LABELED p = t[1] return t[2] if l == p end end nil end |
.flatten_forks(t) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ic_agent/certificate.rb', line 32 def self.flatten_forks(t) if t[0] == NodeId::EMPTY [] elsif t[0] == NodeId::FORK val1 = flatten_forks(t[1]) val2 = flatten_forks(t[2]) val1.concat(val2) val1 else [t] end end |
.lookup(path, cert) ⇒ Object
11 12 13 |
# File 'lib/ic_agent/certificate.rb', line 11 def self.lookup(path, cert) lookup_path(path, cert.value['tree']) end |
.lookup_path(path, tree) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ic_agent/certificate.rb', line 15 def self.lookup_path(path, tree) offset = 0 if path.length == 0 if tree[0] == NodeId::LEAF return tree[1] else return nil end end label = path[0].is_a?(String) ? path[0].encode : path[0] t = find_label(label, flatten_forks(tree)) if t offset += 1 lookup_path(path[offset..-1], t) end end |