Module: Win32::Certstore::Mixin::Assertions
- Included in:
- Win32::Certstore, StoreBase
- Defined in:
- lib/win32/certstore/mixin/assertions.rb
Instance Method Summary collapse
-
#lookup_error(failed_operation = nil) ⇒ Object
Common System call errors.
-
#validate!(token) ⇒ Object
Validate certificate name not nil/empty.
-
#validate_certificate(cert_file_path) ⇒ Object
Validate certificate type.
-
#validate_certificate_obj(cert_obj) ⇒ Object
Validate certificate Object.
-
#validate_store(store_name) ⇒ Object
Validate certificate store name.
-
#validate_thumbprint(cert_thumbprint) ⇒ Object
Validate thumbprint.
Instance Method Details
#lookup_error(failed_operation = nil) ⇒ Object
Common System call errors
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# 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) ⇒ Object
Validate certificate name not nil/empty
52 53 54 |
# 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) ⇒ Object
Validate certificate type
31 32 33 34 35 |
# 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) ⇒ Object
Validate certificate Object
38 39 40 41 42 |
# 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. This is not a properly formatted x509 object" end end |
#validate_store(store_name) ⇒ Object
Validate certificate store name
24 25 26 27 28 |
# 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) ⇒ Object
Validate thumbprint
45 46 47 48 49 |
# File 'lib/win32/certstore/mixin/assertions.rb', line 45 def validate_thumbprint(cert_thumbprint) if cert_thumbprint.nil? || cert_thumbprint.empty? || cert_thumbprint.strip.empty? || cert_thumbprint.length < 40 raise ArgumentError, "Invalid certificate thumbprint." end end |