Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
744 additions
and
44 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
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
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
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,84 @@ | ||
import { AsnProp, AsnPropTypes, AsnType, AsnTypeTypes, OctetString } from "@peculiar/asn1-schema"; | ||
import { ContentType, ContentEncryptionAlgorithmIdentifier } from "./types"; | ||
|
||
/** | ||
* ```asn | ||
* EncryptedContent ::= OCTET STRING | ||
* ``` | ||
*/ | ||
export type PrimitiveEncryptedContent = OctetString; | ||
|
||
/** | ||
* ```asn | ||
* EncryptedContent ::= OCTET STRING | ||
* ``` | ||
*/ | ||
@AsnType({ type: AsnTypeTypes.Choice }) | ||
export class EncryptedContent { | ||
|
||
@AsnProp({ type: OctetString }) | ||
public single?: OctetString; | ||
|
||
@AsnProp({ type: AsnPropTypes.Any }) | ||
public any?: ArrayBuffer; | ||
|
||
constructor(params: Partial<EncryptedContent> = {}) { | ||
Object.assign(this, params); | ||
} | ||
} | ||
|
||
export class ImplicitEncryptedContentInfo { | ||
|
||
@AsnProp({ type: AsnPropTypes.ObjectIdentifier }) | ||
public contentType: ContentType = ""; | ||
|
||
@AsnProp({ type: ContentEncryptionAlgorithmIdentifier }) | ||
public contentEncryptionAlgorithm = new ContentEncryptionAlgorithmIdentifier(); | ||
|
||
@AsnProp({ type: OctetString, context: 0, implicit: true, optional: true }) | ||
public encryptedContent?: PrimitiveEncryptedContent; | ||
|
||
constructor(params: Partial<ImplicitEncryptedContentInfo> = {}) { | ||
Object.assign(this, params); | ||
} | ||
} | ||
|
||
export class ExplicitEncryptedContentInfo { | ||
|
||
@AsnProp({ type: AsnPropTypes.ObjectIdentifier }) | ||
public contentType: ContentType = ""; | ||
|
||
@AsnProp({ type: ContentEncryptionAlgorithmIdentifier }) | ||
public contentEncryptionAlgorithm = new ContentEncryptionAlgorithmIdentifier(); | ||
|
||
@AsnProp({ type: EncryptedContent, context: 0, optional: true }) | ||
public encryptedContent?: EncryptedContent; | ||
|
||
constructor(params: Partial<ExplicitEncryptedContentInfo> = {}) { | ||
Object.assign(this, params); | ||
} | ||
} | ||
|
||
/** | ||
* ```asn | ||
* EncryptedContentInfo ::= SEQUENCE { | ||
* contentType ContentType, | ||
* contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier, | ||
* encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL } | ||
* ``` | ||
*/ | ||
@AsnType({ type: AsnTypeTypes.Choice }) | ||
export class EncryptedContentInfo { | ||
|
||
// RFC compliant | ||
@AsnProp({ type: ImplicitEncryptedContentInfo, optional: true }) | ||
public implicitEncryptedContentInfo?: ImplicitEncryptedContentInfo; | ||
|
||
// !!! Non RFC compliant but used by modern crypto libraries | ||
@AsnProp({ type: ExplicitEncryptedContentInfo, optional: true }) | ||
public explicitEncryptedContentInfo?: ExplicitEncryptedContentInfo; | ||
|
||
constructor(params: Partial<EncryptedContentInfo> = {}) { | ||
Object.assign(this, params); | ||
} | ||
} |
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,54 @@ | ||
import { AsnProp, AsnPropTypes, AsnArray, AsnType, AsnTypeTypes } from "@peculiar/asn1-schema"; | ||
import { CMSVersion } from "./types"; | ||
import { Attribute } from "./attribute"; | ||
import { RecipientInfos } from "./recipient_infos"; | ||
import { OriginatorInfo } from "./originator_info"; | ||
import { EncryptedContentInfo } from "./encrypted_content_info"; | ||
|
||
/** | ||
* ```asn | ||
* UnprotectedAttributes ::= SET SIZE (1..MAX) OF Attribute | ||
* ``` | ||
*/ | ||
@AsnType({ type: AsnTypeTypes.Set, itemType: Attribute }) | ||
export class UnprotectedAttributes extends AsnArray<Attribute> { | ||
|
||
constructor(items?: Attribute[]) { | ||
super(items); | ||
|
||
// Set the prototype explicitly. | ||
Object.setPrototypeOf(this, UnprotectedAttributes.prototype); | ||
} | ||
} | ||
|
||
/** | ||
* ```asn | ||
* EnvelopedData ::= SEQUENCE { | ||
* version CMSVersion, | ||
* originatorInfo [0] IMPLICIT OriginatorInfo OPTIONAL, | ||
* recipientInfos RecipientInfos, | ||
* encryptedContentInfo EncryptedContentInfo, | ||
* unprotectedAttrs [1] IMPLICIT UnprotectedAttributes OPTIONAL } | ||
* ``` | ||
*/ | ||
export class EnvelopedData { | ||
|
||
@AsnProp({ type: AsnPropTypes.Integer }) | ||
public version: CMSVersion = CMSVersion.v0; | ||
|
||
@AsnProp({ type: OriginatorInfo, context: 0, implicit: true, optional: true }) | ||
public originatorInfo?: OriginatorInfo; | ||
|
||
@AsnProp({ type: RecipientInfos }) | ||
public recipientInfos = new RecipientInfos(); | ||
|
||
@AsnProp({ type: EncryptedContentInfo }) | ||
public encryptedContentInfo = new EncryptedContentInfo(); | ||
|
||
@AsnProp({ type: UnprotectedAttributes, context: 1, implicit: true, optional: true }) | ||
public unprotectedAttrs?: UnprotectedAttributes; | ||
|
||
constructor(params: Partial<EnvelopedData> = {}) { | ||
Object.assign(this, params); | ||
} | ||
} |
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,55 @@ | ||
import { AsnProp, AsnPropTypes, OctetString } from "@peculiar/asn1-schema"; | ||
import { OtherKeyAttribute } from "./other_key_attribute"; | ||
import { CMSVersion, EncryptedKey, KeyEncryptionAlgorithmIdentifier } from "./types"; | ||
|
||
/** | ||
* ```asn | ||
* KEKIdentifier ::= SEQUENCE { | ||
* keyIdentifier OCTET STRING, | ||
* date GeneralizedTime OPTIONAL, | ||
* other OtherKeyAttribute OPTIONAL } | ||
* ``` | ||
*/ | ||
export class KEKIdentifier { | ||
|
||
@AsnProp({ type: OctetString }) | ||
public keyIdentifier = new OctetString(); | ||
|
||
@AsnProp({ type: AsnPropTypes.GeneralizedTime, optional: true }) | ||
public date?: Date; | ||
|
||
@AsnProp({ type: OtherKeyAttribute, optional: true }) | ||
public other?: OtherKeyAttribute; | ||
|
||
constructor(params: Partial<KEKIdentifier> = {}) { | ||
Object.assign(this, params); | ||
} | ||
} | ||
|
||
/** | ||
* ```asn | ||
* KEKRecipientInfo ::= SEQUENCE { | ||
* version CMSVersion, -- always set to 4 | ||
* kekid KEKIdentifier, | ||
* keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier, | ||
* encryptedKey EncryptedKey } | ||
* ``` | ||
*/ | ||
export class KEKRecipientInfo { | ||
|
||
@AsnProp({ type: AsnPropTypes.Integer }) | ||
public version: CMSVersion = CMSVersion.v4; | ||
|
||
@AsnProp({ type: KEKIdentifier }) | ||
public kekid = new KEKIdentifier(); | ||
|
||
@AsnProp({ type: KeyEncryptionAlgorithmIdentifier }) | ||
public keyEncryptionAlgorithm = new KeyEncryptionAlgorithmIdentifier(); | ||
|
||
@AsnProp({ type: OctetString }) | ||
public encryptedKey: EncryptedKey = new OctetString(); | ||
|
||
constructor(params: Partial<KEKRecipientInfo> = {}) { | ||
Object.assign(this, params); | ||
} | ||
} |
Oops, something went wrong.