Debian Codegraph @

contrib/pgcrypto/sql/pgp-armor.sql

raw
1 --
2 -- PGP Armor
3 --
4
5 select armor('');
6 select armor('test');
7 select encode(dearmor(armor('')), 'escape');
8 select encode(dearmor(armor('zooka')), 'escape');
9
10 select armor('0123456789abcdef0123456789abcdef0123456789abcdef
11 0123456789abcdef0123456789abcdef0123456789abcdef');
12
13 -- lots formatting
14 select encode(dearmor(' a pgp msg:
15
16 -----BEGIN PGP MESSAGE-----
17 Comment: Some junk
18
19 em9va2E=
20
21 =D5cR
22
23 -----END PGP MESSAGE-----'), 'escape');
24
25 -- lots messages
26 select encode(dearmor('
27 wrong packet:
28 -----BEGIN PGP MESSAGE-----
29
30 d3Jvbmc=
31 =vCYP
32 -----END PGP MESSAGE-----
33
34 right packet:
35 -----BEGIN PGP MESSAGE-----
36
37 cmlnaHQ=
38 =nbpj
39 -----END PGP MESSAGE-----
40
41 use only first packet
42 -----BEGIN PGP MESSAGE-----
43
44 d3Jvbmc=
45 =vCYP
46 -----END PGP MESSAGE-----
47 '), 'escape');
48
49 -- bad crc
50 select dearmor('
51 -----BEGIN PGP MESSAGE-----
52
53 em9va2E=
54 =ZZZZ
55 -----END PGP MESSAGE-----
56 ');
57
58 -- corrupt (no space after the colon)
59 select * from pgp_armor_headers('
60 -----BEGIN PGP MESSAGE-----
61 foo:
62
63 em9va2E=
64 =ZZZZ
65 -----END PGP MESSAGE-----
66 ');
67
68 -- corrupt (no empty line)
69 select * from pgp_armor_headers('
70 -----BEGIN PGP MESSAGE-----
71 em9va2E=
72 =ZZZZ
73 -----END PGP MESSAGE-----
74 ');
75
76 -- no headers
77 select * from pgp_armor_headers('
78 -----BEGIN PGP MESSAGE-----
79
80 em9va2E=
81 =ZZZZ
82 -----END PGP MESSAGE-----
83 ');
84
85 -- header with empty value
86 select * from pgp_armor_headers('
87 -----BEGIN PGP MESSAGE-----
88 foo:
89
90 em9va2E=
91 =ZZZZ
92 -----END PGP MESSAGE-----
93 ');
94
95 -- simple
96 select * from pgp_armor_headers('
97 -----BEGIN PGP MESSAGE-----
98 fookey: foovalue
99 barkey: barvalue
100
101 em9va2E=
102 =ZZZZ
103 -----END PGP MESSAGE-----
104 ');
105
106 -- insane keys, part 1
107 select * from pgp_armor_headers('
108 -----BEGIN PGP MESSAGE-----
109 insane:key :
110
111 em9va2E=
112 =ZZZZ
113 -----END PGP MESSAGE-----
114 ');
115
116 -- insane keys, part 2
117 select * from pgp_armor_headers('
118 -----BEGIN PGP MESSAGE-----
119 insane:key : text value here
120
121 em9va2E=
122 =ZZZZ
123 -----END PGP MESSAGE-----
124 ');
125
126 -- long value
127 select * from pgp_armor_headers('
128 -----BEGIN PGP MESSAGE-----
129 long: this value is more than 76 characters long, but it should still parse correctly as that''s permitted by RFC 4880
130
131 em9va2E=
132 =ZZZZ
133 -----END PGP MESSAGE-----
134 ');
135
136 -- long value, split up
137 select * from pgp_armor_headers('
138 -----BEGIN PGP MESSAGE-----
139 long: this value is more than 76 characters long, but it should still
140 long: parse correctly as that''s permitted by RFC 4880
141
142 em9va2E=
143 =ZZZZ
144 -----END PGP MESSAGE-----
145 ');
146
147 -- long value, split up, part 2
148 select * from pgp_armor_headers('
149 -----BEGIN PGP MESSAGE-----
150 long: this value is more than
151 long: 76 characters long, but it should still
152 long: parse correctly as that''s permitted by RFC 4880
153
154 em9va2E=
155 =ZZZZ
156 -----END PGP MESSAGE-----
157 ');
158
159 -- long value, split up, part 3
160 select * from pgp_armor_headers('
161 -----BEGIN PGP MESSAGE-----
162 emptykey:
163 long: this value is more than
164 emptykey:
165 long: 76 characters long, but it should still
166 emptykey:
167 long: parse correctly as that''s permitted by RFC 4880
168 emptykey:
169
170 em9va2E=
171 =ZZZZ
172 -----END PGP MESSAGE-----
173 ');
174
175 select * from pgp_armor_headers('
176 -----BEGIN PGP MESSAGE-----
177 Comment: dat1.blowfish.sha1.mdc.s2k3.z0
178
179 jA0EBAMCfFNwxnvodX9g0jwB4n4s26/g5VmKzVab1bX1SmwY7gvgvlWdF3jKisvS
180 yA6Ce1QTMK3KdL2MPfamsTUSAML8huCJMwYQFfE=
181 =JcP+
182 -----END PGP MESSAGE-----
183 ');
184
185 -- test CR+LF line endings
186 select * from pgp_armor_headers(replace('
187 -----BEGIN PGP MESSAGE-----
188 fookey: foovalue
189 barkey: barvalue
190
191 em9va2E=
192 =ZZZZ
193 -----END PGP MESSAGE-----
194 ', E'\n', E'\r\n'));
195
196 -- test header generation
197 select armor('zooka', array['foo'], array['bar']);
198 select armor('zooka', array['Version', 'Comment'], array['Created by pgcrypto', 'PostgreSQL, the world''s most advanced open source database']);
199 select * from pgp_armor_headers(
200 armor('zooka', array['Version', 'Comment'],
201 array['Created by pgcrypto', 'PostgreSQL, the world''s most advanced open source database']));
202
203 -- error/corner cases
204 select armor('', array['foo'], array['too', 'many']);
205 select armor('', array['too', 'many'], array['foo']);
206 select armor('', array[['']], array['foo']);
207 select armor('', array['foo'], array[['']]);
208 select armor('', array[null], array['foo']);
209 select armor('', array['foo'], array[null]);
210 select armor('', '[0:0]={"foo"}', array['foo']);
211 select armor('', array['foo'], '[0:0]={"foo"}');
212 select armor('', array[E'embedded\nnewline'], array['foo']);
213 select armor('', array['foo'], array[E'embedded\nnewline']);
214 select armor('', array['embedded: colon+space'], array['foo']);