-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extKeyUsage convenience mutators to builders
- Loading branch information
Showing
4 changed files
with
94 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// ExtensionKeyUsage.swift | ||
// Shield | ||
// | ||
// Copyright © 2019 Outfox, inc. | ||
// | ||
// | ||
// Distributed under the MIT License, See LICENSE for details. | ||
// | ||
|
||
import Foundation | ||
import PotentASN1 | ||
import ShieldOID | ||
|
||
|
||
public struct ExtKeyUsage: Equatable, Hashable, Codable, ExtensionValue { | ||
|
||
public static var extensionID = iso_itu.ds.certificateExtension.extKeyUsage.oid | ||
public static var asn1Schema = Schemas.extKeyUsageExtension | ||
|
||
public let keyPurposes: Set<OID> | ||
|
||
public init(keyPurposes: Set<OID>) { | ||
self.keyPurposes = keyPurposes | ||
} | ||
} | ||
|
||
|
||
|
||
// MARK: Schemas | ||
|
||
public extension Schemas { | ||
|
||
static let extKeyUsageExtension: Schema = .sequenceOf(.objectIdentifier()) | ||
|
||
} | ||
|
||
|
||
// MARK: KeyUsage Conformances | ||
|
||
extension ExtKeyUsage { | ||
|
||
public init(from decoder: Decoder) throws { | ||
var container = try decoder.unkeyedContainer() | ||
var keyPurposes = Set<OID>() | ||
for _ in 0 ..< (container.count ?? 0) { | ||
keyPurposes.insert(try container.decode(OID.self)) | ||
} | ||
self.keyPurposes = keyPurposes | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.unkeyedContainer() | ||
for keyPurpose in keyPurposes { | ||
try container.encode(keyPurpose) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters