Module: Asn1Parser
- Defined in:
- lib/asn1_parser.rb,
lib/asn1_parser/engine.rb,
lib/asn1_parser/version.rb
Overview
Main module of ASN1 Parser gem
Defined Under Namespace
Classes: Engine
Constant Summary collapse
- VERSION =
'0.1.1'
Class Method Summary collapse
Class Method Details
.cdr(list) ⇒ Object
48 49 50 |
# File 'lib/asn1_parser.rb', line 48 def self.cdr(list) list[1..list.length] end |
.makehash(array) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/asn1_parser.rb', line 30 def self.makehash(array) hash = {} (0..(array.length - 1)).step(2) do |i| cd = CharDet.detect(array[i]) cd['encoding'] = cd['encoding'] || 'utf-8' hash[array[i + 1]] = array[i]&.force_encoding(cd['encoding']) end hash end |
.parse(filepath) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/asn1_parser.rb', line 9 def self.parse(filepath) crt_encoded = File.open(filepath).read obj = OpenSSL::ASN1.decode(crt_encoded) gacc = [] collect = lambda { |obj, acc| if obj.nil? gacc elsif obj.respond_to?('[]') collect.call(obj[0], collect.call(cdr(obj), acc)) elsif obj.value.is_a? String gacc.push(obj.value) elsif obj.value.respond_to?('[]') collect.call(obj.value[0], collect.call(cdr(obj.value), acc)) end } collect.call(obj, []) gacc end |
.printhash(hash) ⇒ Object
42 43 44 45 46 |
# File 'lib/asn1_parser.rb', line 42 def self.printhash(hash) hash.each do |key, value| puts "#{key} => #{value}" end end |