lib/app_info/android/signatures/v1.rb in app-info-3.0.0.beta1 vs lib/app_info/android/signatures/v1.rb in app-info-3.0.0.beta2

- old
+ new

@@ -1,59 +1,63 @@ # frozen_string_literal: true -module AppInfo::Android::Signature - # Android v1 Signature - class V1 < Base - DESCRIPTION = 'JAR signing' +module AppInfo + class Android < File + module Signature + # Android v1 Signature + class V1 < Base + DESCRIPTION = 'JAR signing' - PKCS7_HEADER = [0x30, 0x82].freeze + PKCS7_HEADER = [0x30, 0x82].freeze - attr_reader :certificates, :signatures + attr_reader :certificates, :signatures - def version - Version::V1 - end + def version + Version::V1 + end - def description - DESCRIPTION - end + def description + DESCRIPTION + end - def verify - @signatures = fetch_signatures - @certificates = fetch_certificates + def verify + @signatures = fetch_signatures + @certificates = fetch_certificates - raise NotFoundError, 'Not found certificates' if @certificates.empty? - end + raise NotFoundError, 'Not found certificates' if @certificates.empty? + end - private + private - def fetch_signatures - case @parser - when AppInfo::APK - signatures_from(@parser.apk) - when AppInfo::AAB - signatures_from(@parser) - end - end + def fetch_signatures + case @parser + when AppInfo::APK + signatures_from(@parser.apk) + when AppInfo::AAB + signatures_from(@parser) + end + end - def fetch_certificates - @signatures.each_with_object([]) do |(_, sign), obj| - next if sign.certificates.empty? + def fetch_certificates + @signatures.each_with_object([]) do |(_, sign), obj| + next if sign.certificates.empty? - obj << AppInfo::Certificate.new(sign.certificates[0]) - end - end + obj << AppInfo::Certificate.new(sign.certificates[0]) + end + end - def signatures_from(parser) - signs = {} - parser.each_file do |path, data| - # find META-INF/xxx.{RSA|DSA|EC} - next unless path =~ %r{^META-INF/} && data.unpack('CC') == PKCS7_HEADER + def signatures_from(parser) + signs = {} + parser.each_file do |path, data| + # find META-INF/xxx.{RSA|DSA|EC} + next unless path =~ %r{^META-INF/} && data.unpack('CC') == PKCS7_HEADER - signs[path] = OpenSSL::PKCS7.new(data) + signs[path] = OpenSSL::PKCS7.new(data) + end + signs + end end - signs + + register(Version::V1, V1) end end - - register(Version::V1, V1) end