module Win32::Certstore::Mixin::Assertions
Public Instance Methods
lookup_error(failed_operation = nil)
click to toggle source
Common System call errors
# File lib/win32/certstore/mixin/assertions.rb, line 57 def lookup_error(failed_operation = nil) error_no = FFI::LastError.error case error_no when 1223 raise SystemCallError.new("The operation was canceled by the user", error_no) when -2146885628 raise SystemCallError.new("Cannot find object or property", error_no) when -2146885629 raise SystemCallError.new("An error occurred while reading or writing to a file.", error_no) when -2146881269 raise SystemCallError.new("ASN1 bad tag value met. -- Is the certificate in DER format?", error_no) when -2146881278 raise SystemCallError.new("ASN1 unexpected end of data.", error_no) when -2147024891 raise SystemCallError.new("System.UnauthorizedAccessException, Access denied..", error_no) else raise SystemCallError.new("Unable to #{failed_operation} certificate.", error_no) end end
validate!(token)
click to toggle source
Validate certificate name not nil/empty
# File lib/win32/certstore/mixin/assertions.rb, line 52 def validate!(token) raise ArgumentError, "Invalid search token" if !token || token.strip.empty? end
validate_certificate(cert_file_path)
click to toggle source
Validate certificate type
# File lib/win32/certstore/mixin/assertions.rb, line 31 def validate_certificate(cert_file_path) unless !cert_file_path.nil? && File.extname(cert_file_path) =~ /.cer|.crt|.pfx|.der/ raise ArgumentError, "Invalid Certificate format." end end
validate_certificate_obj(cert_obj)
click to toggle source
Validate certificate Object
# File lib/win32/certstore/mixin/assertions.rb, line 38 def validate_certificate_obj(cert_obj) unless cert_obj.class == OpenSSL::X509::Certificate raise ArgumentError, "Invalid Certificate object." end end
validate_store(store_name)
click to toggle source
Validate certificate store name
# File lib/win32/certstore/mixin/assertions.rb, line 24 def validate_store(store_name) if store_name.to_s.strip.empty? raise ArgumentError, "Empty Certificate Store." end end
validate_thumbprint(cert_thumbprint)
click to toggle source
Validate thumbprint
# File lib/win32/certstore/mixin/assertions.rb, line 45 def validate_thumbprint(cert_thumbprint) if cert_thumbprint.nil? || cert_thumbprint.strip.empty? raise ArgumentError, "Invalid certificate thumbprint." end end
Private Instance Methods
valid_store_name()
click to toggle source
These Are Valid certificate store name CA -> Certification authority certificates. MY -> A certificate store that holds certificates with associated private keys. ROOT -> Root certificates. SPC -> Software Publisher Certificate.
# File lib/win32/certstore/mixin/assertions.rb, line 84 def valid_store_name %w{MY CA ROOT AUTHROOT DISALLOWED SPC TRUST TRUSTEDPEOPLE TRUSTEDPUBLISHER CLIENTAUTHISSUER TRUSTEDDEVICES SMARTCARDROOT WEBHOSTING REMOTE\ DESKTOP} end