class TrustStore
Represents transport-neutral trusted certificate sources.
Definitions
def self.load(path, **options)
Load a PEM-encoded certificate bundle from the given path.
Signature
-
parameter
pathString | Interface(:to_path) The path to the certificate bundle.
-
parameter
optionsHash Options forwarded to
.parse.-
returns
TrustStore The loaded trust store.
Implementation
def self.load(path, **options)
return parse(File.read(path), **options)
end
def self.parse(certificate_bundle, system_certificates: false)
Parse a PEM-encoded certificate bundle into a trust store.
Signature
-
parameter
certificate_bundleString One or more trusted certificates encoded as PEM.
-
parameter
system_certificatesBoolean Whether system-provided trusted certificates should be included.
-
returns
TrustStore The parsed trust store.
-
raises
ArgumentError If the bundle does not contain any certificates.
-
raises
TypeError If the bundle is not a string.
Implementation
def self.parse(certificate_bundle, system_certificates: false)
return self.new(certificates: Certificates.parse(certificate_bundle), system_certificates: system_certificates)
end
def initialize(certificates: [], system_certificates: false)
Initialize a trust store from PEM-encoded trusted certificates.
Signature
-
parameter
certificatesArray(String) The trusted certificates encoded as PEM.
-
parameter
system_certificatesBoolean Whether system-provided trusted certificates should be included.
-
raises
ArgumentError If no source of trusted certificates is specified.
-
raises
TypeError If certificates are not provided as strings.
Implementation
def initialize(certificates: [], system_certificates: false)
unless certificates.is_a?(Array) && certificates.all?{|certificate| certificate.is_a?(String)}
raise TypeError, "Certificates must be provided as an array of strings!"
end
unless certificates.any? || system_certificates
raise ArgumentError, "At least one source of trusted certificates must be specified!"
end
@certificates = certificates
@system_certificates = system_certificates
end
attr :certificates
Signature
-
attribute
Array(String) The individual trusted certificates encoded as PEM.
def system_certificates?
Whether system-provided trusted certificates should be included.
Signature
-
returns
Boolean trueif system-provided trusted certificates should be included.
Implementation
def system_certificates?
@system_certificates
end
def inspect
Get a representation of the trust store without exposing certificate material.
Signature
-
returns
String A redacted representation of the trust store.
Implementation
def inspect
attributes = {
certificates: @certificates.size,
system_certificates: @system_certificates,
}
return "\#<#{self.class} #{attributes.inspect}>"
end