module Asn1Parser
Main module of ASN1 Parser gem
Constants
- VERSION
Public Class Methods
cdr(list)
click to toggle source
# File lib/asn1_parser.rb, line 48 def self.cdr(list) list[1..list.length] end
makehash(array)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/asn1_parser.rb, line 42 def self.printhash(hash) hash.each do |key, value| puts "#{key} => #{value}" end end