summaryrefslogtreecommitdiffstats
path: root/openpgp/src/message/grammar.lalrpop
blob: f98b3786c292aecb57411ebd26c003477f604c9f (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// -*- mode: Rust; -*-

use crate::message::lexer;

grammar;

pub Message: () = {
    LITERAL,
    CompressedData,
    EncryptedPart,
    SignedPart,
    OPAQUE_CONTENT,
};

CompressedData: () = {
    COMPRESSED_DATA Message POP
};

Seipv1Part: () = {
    SEIPv1 Message MDC POP,
    SEIPv1 OPAQUE_CONTENT POP,
}

AedPart: () = {
    AED Message POP,
}

// An encrypted part is 0 or more ESKs followed by an encryption container.
EncryptedPart: () = {
    EncryptionContainer,
    ESKS EncryptionContainer,
};

EncryptionContainer: () = {
    Seipv1Part,
    AedPart,
};

ESKS: () = {
    ESK,
    ESKS ESK,
};

ESK: () = {
    PKESK,
    SKESK,
};

// Signatures bracket a message like so:
//
//   OPS OPS Message SIG SIG
//
// or, there are 1 or more signatures preceding a Message (this is an
// artifact of old PGP versions):
//
//   SIG SIG Message
SignedPart: () = {
    SIG Message,
    OPS Message SIG,
}

extern {
    type Location = usize;
    type Error = lexer::LexicalError;

    enum lexer::Token {
        LITERAL => lexer::Token::Literal,
        COMPRESSED_DATA => lexer::Token::CompressedData,
        SKESK => lexer::Token::SKESK,
        PKESK => lexer::Token::PKESK,
        SEIPv1 => lexer::Token::SEIPv1,
        MDC => lexer::Token::MDC,
        AED => lexer::Token::AED,
        OPS => lexer::Token::OPS,
        SIG => lexer::Token::SIG,
        POP => lexer::Token::Pop,
        OPAQUE_CONTENT => lexer::Token::OpaqueContent,
    }
}