mirror of
https://github.com/apple/swift-certificates
synced 2026-11-27 04:54:20 +00:00
CryptographicMessageSyntax types
This commit is contained in:
1 parent
38147aaae1
commit
ef35326c8a
7 files changed
+234
No files matched your search
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftCertificates open source project
|
||||
//
|
||||
// Copyright (c) 2023 Apple Inc. and the SwiftCertificates project authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftCertificates project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import SwiftASN1
|
||||
|
||||
/// ``ContentInfo`` is defined in ASN.1 as:
|
||||
/// ```
|
||||
/// ContentInfo ::= SEQUENCE {
|
||||
/// contentType ContentType,
|
||||
/// content [0] EXPLICIT ANY DEFINED BY contentType }
|
||||
/// ContentType ::= OBJECT IDENTIFIER
|
||||
/// ```
|
||||
enum CMSContentInfo {
|
||||
case signedData(CMSSignedData)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftCertificates open source project
|
||||
//
|
||||
// Copyright (c) 2023 Apple Inc. and the SwiftCertificates project authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftCertificates project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import SwiftASN1
|
||||
|
||||
/// ``CMSEncapsulatedContentInfo`` is defined in ASN.1 as:
|
||||
/// ```
|
||||
/// EncapsulatedContentInfo ::= SEQUENCE {
|
||||
/// eContentType ContentType,
|
||||
/// eContent [0] EXPLICIT OCTET STRING OPTIONAL }
|
||||
/// ContentType ::= OBJECT IDENTIFIER
|
||||
/// ```
|
||||
struct CMSEncapsulatedContentInfo {
|
||||
var eContentType: ASN1ObjectIdentifier
|
||||
var eContent: ASN1OctetString?
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftCertificates open source project
|
||||
//
|
||||
// Copyright (c) 2023 Apple Inc. and the SwiftCertificates project authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftCertificates project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import SwiftASN1
|
||||
|
||||
/// ``CMSIssuerAndSerialNumber`` is defined in ASN.1 as:
|
||||
/// ```
|
||||
/// IssuerAndSerialNumber ::= SEQUENCE {
|
||||
/// issuer Name,
|
||||
/// serialNumber CertificateSerialNumber }
|
||||
/// ```
|
||||
/// The definition of `Name` is taken from X.501 [X.501-88], and the
|
||||
/// definition of `CertificateSerialNumber` is taken from X.509 [X.509-97].
|
||||
struct CMSIssuerAndSerialNumber {
|
||||
var issuer: DistinguishedName
|
||||
var serialNumber: Certificate.SerialNumber
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftCertificates open source project
|
||||
//
|
||||
// Copyright (c) 2023 Apple Inc. and the SwiftCertificates project authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftCertificates project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import SwiftASN1
|
||||
|
||||
/// ``SignedData`` is defined in ASN.1 as:
|
||||
/// ```
|
||||
/// SignedData ::= SEQUENCE {
|
||||
/// version CMSVersion,
|
||||
/// digestAlgorithms DigestAlgorithmIdentifiers,
|
||||
/// encapContentInfo EncapsulatedContentInfo,
|
||||
/// certificates [0] IMPLICIT CertificateSet OPTIONAL,
|
||||
/// crls [1] IMPLICIT RevocationInfoChoices OPTIONAL,
|
||||
/// signerInfos SignerInfos }
|
||||
///
|
||||
/// DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier
|
||||
/// DigestAlgorithmIdentifier ::= AlgorithmIdentifier
|
||||
/// SignerInfos ::= SET OF SignerInfo
|
||||
///
|
||||
/// CertificateChoices ::= CHOICE {
|
||||
/// certificate Certificate,
|
||||
/// extendedCertificate [0] IMPLICIT ExtendedCertificate, -- Obsolete
|
||||
/// v1AttrCert [1] IMPLICIT AttributeCertificateV1, -- Obsolete
|
||||
/// v2AttrCert [2] IMPLICIT AttributeCertificateV2,
|
||||
/// other [3] IMPLICIT OtherCertificateFormat }
|
||||
///
|
||||
/// OtherCertificateFormat ::= SEQUENCE {
|
||||
/// otherCertFormat OBJECT IDENTIFIER,
|
||||
/// otherCert ANY DEFINED BY otherCertFormat }
|
||||
/// ```
|
||||
struct CMSSignedData {
|
||||
var version: CMSVersion
|
||||
var digestAlgorithms: [AlgorithmIdentifier]
|
||||
var encapContentInfo: CMSEncapsulatedContentInfo
|
||||
var certificates: [Certificate]?
|
||||
var signerInfos: [CMSSignerInfo]
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftCertificates open source project
|
||||
//
|
||||
// Copyright (c) 2023 Apple Inc. and the SwiftCertificates project authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftCertificates project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import SwiftASN1
|
||||
|
||||
/// ``CMSSignerIdentifier`` is defined in ASN.1 as:
|
||||
/// ```
|
||||
/// SignerIdentifier ::= CHOICE {
|
||||
/// issuerAndSerialNumber IssuerAndSerialNumber,
|
||||
/// subjectKeyIdentifier [0] SubjectKeyIdentifier }
|
||||
/// ```
|
||||
enum CMSSignerIdentifier {
|
||||
case issuerAndSerialNumber(CMSIssuerAndSerialNumber)
|
||||
case subjectKeyIdentifier(Certificate.Extensions.SubjectKeyIdentifier)
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftCertificates open source project
|
||||
//
|
||||
// Copyright (c) 2023 Apple Inc. and the SwiftCertificates project authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftCertificates project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import SwiftASN1
|
||||
|
||||
/// ``CMSSignerInfo`` is defined in ASN.1 as:
|
||||
/// ```
|
||||
/// SignerInfo ::= SEQUENCE {
|
||||
/// version CMSVersion,
|
||||
/// sid SignerIdentifier,
|
||||
/// digestAlgorithm DigestAlgorithmIdentifier,
|
||||
/// signedAttrs [0] IMPLICIT SignedAttributes OPTIONAL,
|
||||
/// signatureAlgorithm SignatureAlgorithmIdentifier,
|
||||
/// signature SignatureValue,
|
||||
/// unsignedAttrs [1] IMPLICIT UnsignedAttributes OPTIONAL }
|
||||
///
|
||||
/// SignatureValue ::= OCTET STRING
|
||||
/// DigestAlgorithmIdentifier ::= AlgorithmIdentifier
|
||||
/// SignatureAlgorithmIdentifier ::= AlgorithmIdentifier
|
||||
/// ```
|
||||
/// - Note: If the `SignerIdentifier` is the CHOICE `issuerAndSerialNumber`,
|
||||
/// then the `version` MUST be 1. If the `SignerIdentifier` is `subjectKeyIdentifier`,
|
||||
/// then the `version` MUST be 3.
|
||||
struct CMSSignerInfo {
|
||||
var version: CMSVersion
|
||||
var signerIdentifier: CMSSignerIdentifier
|
||||
var digestAlgorithm: AlgorithmIdentifier
|
||||
var signatureAlgorithm: AlgorithmIdentifier
|
||||
var signature: ASN1OctetString
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftCertificates open source project
|
||||
//
|
||||
// Copyright (c) 2023 Apple Inc. and the SwiftCertificates project authors
|
||||
// Licensed under Apache License v2.0
|
||||
//
|
||||
// See LICENSE.txt for license information
|
||||
// See CONTRIBUTORS.txt for the list of SwiftCertificates project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import SwiftASN1
|
||||
|
||||
/// ``CMPVersion`` is defined in ASN1. as:
|
||||
/// ```
|
||||
/// CMSVersion ::= INTEGER
|
||||
/// { v0(0), v1(1), v2(2), v3(3), v4(4), v5(5) }
|
||||
/// ```
|
||||
struct CMSVersion: RawRepresentable, Hashable {
|
||||
var rawValue: Int
|
||||
|
||||
static let v0 = Self(rawValue: 0)
|
||||
static let v1 = Self(rawValue: 1)
|
||||
static let v2 = Self(rawValue: 2)
|
||||
static let v3 = Self(rawValue: 3)
|
||||
static let v4 = Self(rawValue: 4)
|
||||
static let v5 = Self(rawValue: 5)
|
||||
}
|
||||
|
||||
extension CMSVersion: CustomStringConvertible {
|
||||
var description: String {
|
||||
"CMSv\(rawValue)"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user