-
Notifications
You must be signed in to change notification settings - Fork 48
/
msg-block.ts
44 lines (37 loc) · 1.56 KB
/
msg-block.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* ©️ 2016 - present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com */
'use strict';
import { DecryptError, VerifyRes } from './crypto/pgp/msg-util.js';
import { AttachmentMeta } from './attachment.js';
import { Buf } from './buf.js';
export type KeyBlockType = 'publicKey' | 'privateKey' | 'certificate' | 'pkcs12' | 'pkcs8EncryptedPrivateKey' | 'pkcs8PrivateKey' | 'pkcs8RsaPrivateKey';
export type ReplaceableMsgBlockType = KeyBlockType | 'signedMsg' | 'encryptedMsg' | 'pkcs7';
export type MsgBlockType =
| ReplaceableMsgBlockType
| 'plainText'
| 'signedText'
| 'plainHtml'
| 'decryptedHtml'
| 'plainAttachment'
| 'encryptedAttachment'
| 'decryptedAttachment'
| 'encryptedAttachmentLink'
| 'decryptErr'
| 'verifiedMsg'
| 'signedHtml';
export class MsgBlock {
public constructor(
public type: MsgBlockType,
public content: string | Buf,
public complete: boolean,
public signature?: string,
public attachmentMeta?: AttachmentMeta, // only in plainAttachment, encryptedAttachment, decryptedAttachment, encryptedAttachmentLink (not sure if always)
public decryptErr?: DecryptError, // only in decryptErr block, always
public verifyRes?: VerifyRes
) {}
public static fromContent = (type: MsgBlockType, content: string | Buf, missingEnd = false): MsgBlock => {
return new MsgBlock(type, content, !missingEnd);
};
public static fromAttachment = (type: MsgBlockType, content: string, attachmentMeta: AttachmentMeta): MsgBlock => {
return new MsgBlock(type, content, true, undefined, attachmentMeta);
};
}