AlamofireExtension

public struct AlamofireExtension<ExtendedType>

Type that acts as a generic extension point for all AlamofireExtended types.

  • Stores the type or meta-type of any extended type.

    Declaration

    Swift

    public private(set) var type: ExtendedType { get }
  • Create an instance from the provided value.

    Declaration

    Swift

    public init(_ type: ExtendedType)

    Parameters

    type

    Instance being extended.

Available where ExtendedType: URLSessionConfiguration

  • Alamofire’s default configuration. Same as URLSessionConfiguration.default but adds Alamofire default Accept-Language, Accept-Encoding, and User-Agent headers.

    Declaration

    Swift

    public static var `default`: URLSessionConfiguration { get }
  • .ephemeral configuration with Alamofire’s default Accept-Language, Accept-Encoding, and User-Agent headers.

    Declaration

    Swift

    public static var ephemeral: URLSessionConfiguration { get }

Available where ExtendedType: Bundle

  • Returns all valid cer, crt, and der certificates in the bundle.

    Declaration

    Swift

    public var certificates: [SecCertificate] { get }
  • Returns all public keys for the valid certificates in the bundle.

    Declaration

    Swift

    public var publicKeys: [SecKey] { get }
  • Returns all pathnames for the resources identified by the provided file extensions.

    Declaration

    Swift

    public func paths(forResourcesOfTypes types: [String]) -> [String]

    Parameters

    types

    The filename extensions locate.

    Return Value

    All pathnames for the given filename extensions.

Available where ExtendedType == SecTrust

  • Evaluates self after applying the SecPolicy value provided.

    Throws

    Any Error from applying the SecPolicy or from evaluation.

    Declaration

    Swift

    @available(iOS 12, macOS 10.14, tvOS 12, watchOS 5, *)
    public func evaluate(afterApplying policy: SecPolicy) throws

    Parameters

    policy

    The SecPolicy to apply to self before evaluation.

  • Attempts to validate self using the SecPolicy provided and transforming any error produced using the closure passed.

    Throws

    Any Error from applying the policy, or the result of errorProducer if validation fails.

    Declaration

    Swift

    @available(iOS, introduced: 10, deprecated: 12, renamed: "evaluate(afterApplying:﹚")
    @available(macOS, introduced: 10.12, deprecated: 10.14, renamed: "evaluate(afterApplying:﹚")
    @available(tvOS, introduced: 10, deprecated: 12, renamed: "evaluate(afterApplying:﹚")
    @available(watchOS, introduced: 3, deprecated: 5, renamed: "evaluate(afterApplying:﹚")
    public func validate(policy: SecPolicy, errorProducer: (_ status: OSStatus, _ result: SecTrustResultType) -> Error) throws

    Parameters

    policy

    The SecPolicy used to evaluate self.

    errorProducer

    The closure used transform the failed OSStatus and SecTrustResultType.

  • Applies a SecPolicy to self, throwing if it fails.

    Throws

    An AFError.serverTrustEvaluationFailed instance with a .policyApplicationFailed reason.

    Declaration

    Swift

    public func apply(policy: SecPolicy) throws -> SecTrust

    Parameters

    policy

    The SecPolicy.

    Return Value

    self, with the policy applied.

  • Evaluate self, throwing an Error if evaluation fails.

    Throws

    AFError.serverTrustEvaluationFailed with reason .trustValidationFailed and associated error from the underlying evaluation.

    Declaration

    Swift

    @available(iOS 12, macOS 10.14, tvOS 12, watchOS 5, *)
    public func evaluate() throws
  • Validate self, passing any failure values through errorProducer.

    Throws

    The Error produced by the errorProducer closure.

    Declaration

    Swift

    @available(iOS, introduced: 10, deprecated: 12, renamed: "evaluate(﹚")
    @available(macOS, introduced: 10.12, deprecated: 10.14, renamed: "evaluate(﹚")
    @available(tvOS, introduced: 10, deprecated: 12, renamed: "evaluate(﹚")
    @available(watchOS, introduced: 3, deprecated: 5, renamed: "evaluate(﹚")
    public func validate(errorProducer: (_ status: OSStatus, _ result: SecTrustResultType) -> Error) throws

    Parameters

    errorProducer

    The closure used to transform the failed OSStatus and SecTrustResultType into an Error.

  • Sets a custom certificate chain on self, allowing full validation of a self-signed certificate and its chain.

    Throws

    Any error produced when applying the new certificate chain.

    Declaration

    Swift

    public func setAnchorCertificates(_ certificates: [SecCertificate]) throws

    Parameters

    certificates

    The SecCertificates to add to the chain.

  • The public keys contained in self.

    Declaration

    Swift

    public var publicKeys: [SecKey] { get }
  • The SecCertificates contained in self.

    Declaration

    Swift

    public var certificates: [SecCertificate] { get }
  • The Data values for all certificates contained in self.

    Declaration

    Swift

    public var certificateData: [Data] { get }
  • Validates self after applying SecPolicy.af.default. This evaluation does not validate the hostname.

    Throws

    An AFError.serverTrustEvaluationFailed instance with a .defaultEvaluationFailed reason.

    Declaration

    Swift

    public func performDefaultValidation(forHost host: String) throws

    Parameters

    host

    The hostname, used only in the error output if validation fails.

  • Validates self after applying SecPolicy.af.hostname(host), which performs the default validation as well as hostname validation.

    Throws

    An AFError.serverTrustEvaluationFailed instance with a .defaultEvaluationFailed reason.

    Declaration

    Swift

    public func performValidation(forHost host: String) throws

    Parameters

    host

    The hostname to use in the validation.

Available where ExtendedType == SecPolicy

  • Creates a SecPolicy instance which will validate server certificates but not require a host name match.

    Declaration

    Swift

    public static let `default`: SecPolicy
  • Creates a SecPolicy instance which will validate server certificates and much match the provided hostname.

    Declaration

    Swift

    public static func hostname(_ hostname: String) -> SecPolicy

    Parameters

    hostname

    The hostname to validate against.

    Return Value

    The SecPolicy.

  • Creates a SecPolicy which checks the revocation of certificates.

    Throws

    An AFError.serverTrustEvaluationFailed error with reason .revocationPolicyCreationFailed if the policy cannot be created.

    Declaration

    Swift

    public static func revocation(options: RevocationTrustEvaluator.Options) throws -> SecPolicy

    Parameters

    options

    The RevocationTrustEvaluator.Options for evaluation.

    Return Value

    The SecPolicy.

Available where ExtendedType == [SecCertificate]

  • All Data values for the contained SecCertificates.

    Declaration

    Swift

    public var data: [Data] { get }
  • All public SecKey values for the contained SecCertificates.

    Declaration

    Swift

    public var publicKeys: [SecKey] { get }

Available where ExtendedType == SecCertificate

  • The public key for self, if it can be extracted.

    Note

    On 2020 OSes and newer, only RSA and ECDSA keys are supported.

    Declaration

    Swift

    public var publicKey: SecKey? { get }

Available where ExtendedType == OSStatus

  • Returns whether self is errSecSuccess.

    Declaration

    Swift

    public var isSuccess: Bool { get }

Available where ExtendedType == SecTrustResultType

  • Returns whether self is .unspecified or .proceed.

    Declaration

    Swift

    public var isSuccess: Bool { get }