| 1 |
-- |
| 2 |
-- PGP Armor |
| 3 |
-- |
| 4 |
select armor(''); |
| 5 |
armor |
| 6 |
----------------------------- |
| 7 |
-----BEGIN PGP MESSAGE-----+ |
| 8 |
+ |
| 9 |
=twTO + |
| 10 |
-----END PGP MESSAGE----- + |
| 11 |
|
| 12 |
(1 row) |
| 13 |
|
| 14 |
select armor('test'); |
| 15 |
armor |
| 16 |
----------------------------- |
| 17 |
-----BEGIN PGP MESSAGE-----+ |
| 18 |
+ |
| 19 |
dGVzdA== + |
| 20 |
=+G7Q + |
| 21 |
-----END PGP MESSAGE----- + |
| 22 |
|
| 23 |
(1 row) |
| 24 |
|
| 25 |
select encode(dearmor(armor('')), 'escape'); |
| 26 |
encode |
| 27 |
-------- |
| 28 |
|
| 29 |
(1 row) |
| 30 |
|
| 31 |
select encode(dearmor(armor('zooka')), 'escape'); |
| 32 |
encode |
| 33 |
-------- |
| 34 |
zooka |
| 35 |
(1 row) |
| 36 |
|
| 37 |
select armor('0123456789abcdef0123456789abcdef0123456789abcdef |
| 38 |
0123456789abcdef0123456789abcdef0123456789abcdef'); |
| 39 |
armor |
| 40 |
------------------------------------------------------------------------------ |
| 41 |
-----BEGIN PGP MESSAGE----- + |
| 42 |
+ |
| 43 |
MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmCjAxMjM0NTY3+ |
| 44 |
ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmMDEyMzQ1Njc4OWFiY2RlZg== + |
| 45 |
=JFw5 + |
| 46 |
-----END PGP MESSAGE----- + |
| 47 |
|
| 48 |
(1 row) |
| 49 |
|
| 50 |
-- lots formatting |
| 51 |
select encode(dearmor(' a pgp msg: |
| 52 |
|
| 53 |
-----BEGIN PGP MESSAGE----- |
| 54 |
Comment: Some junk |
| 55 |
|
| 56 |
em9va2E= |
| 57 |
|
| 58 |
=D5cR |
| 59 |
|
| 60 |
-----END PGP MESSAGE-----'), 'escape'); |
| 61 |
encode |
| 62 |
-------- |
| 63 |
zooka |
| 64 |
(1 row) |
| 65 |
|
| 66 |
-- lots messages |
| 67 |
select encode(dearmor(' |
| 68 |
wrong packet: |
| 69 |
-----BEGIN PGP MESSAGE----- |
| 70 |
|
| 71 |
d3Jvbmc= |
| 72 |
=vCYP |
| 73 |
-----END PGP MESSAGE----- |
| 74 |
|
| 75 |
right packet: |
| 76 |
-----BEGIN PGP MESSAGE----- |
| 77 |
|
| 78 |
cmlnaHQ= |
| 79 |
=nbpj |
| 80 |
-----END PGP MESSAGE----- |
| 81 |
|
| 82 |
use only first packet |
| 83 |
-----BEGIN PGP MESSAGE----- |
| 84 |
|
| 85 |
d3Jvbmc= |
| 86 |
=vCYP |
| 87 |
-----END PGP MESSAGE----- |
| 88 |
'), 'escape'); |
| 89 |
encode |
| 90 |
-------- |
| 91 |
right |
| 92 |
(1 row) |
| 93 |
|
| 94 |
-- bad crc |
| 95 |
select dearmor(' |
| 96 |
-----BEGIN PGP MESSAGE----- |
| 97 |
|
| 98 |
em9va2E= |
| 99 |
=ZZZZ |
| 100 |
-----END PGP MESSAGE----- |
| 101 |
'); |
| 102 |
ERROR: Corrupt ascii-armor |
| 103 |
-- corrupt (no space after the colon) |
| 104 |
select * from pgp_armor_headers(' |
| 105 |
-----BEGIN PGP MESSAGE----- |
| 106 |
foo: |
| 107 |
|
| 108 |
em9va2E= |
| 109 |
=ZZZZ |
| 110 |
-----END PGP MESSAGE----- |
| 111 |
'); |
| 112 |
ERROR: Corrupt ascii-armor |
| 113 |
-- corrupt (no empty line) |
| 114 |
select * from pgp_armor_headers(' |
| 115 |
-----BEGIN PGP MESSAGE----- |
| 116 |
em9va2E= |
| 117 |
=ZZZZ |
| 118 |
-----END PGP MESSAGE----- |
| 119 |
'); |
| 120 |
ERROR: Corrupt ascii-armor |
| 121 |
-- no headers |
| 122 |
select * from pgp_armor_headers(' |
| 123 |
-----BEGIN PGP MESSAGE----- |
| 124 |
|
| 125 |
em9va2E= |
| 126 |
=ZZZZ |
| 127 |
-----END PGP MESSAGE----- |
| 128 |
'); |
| 129 |
key | value |
| 130 |
-----+------- |
| 131 |
(0 rows) |
| 132 |
|
| 133 |
-- header with empty value |
| 134 |
select * from pgp_armor_headers(' |
| 135 |
-----BEGIN PGP MESSAGE----- |
| 136 |
foo: |
| 137 |
|
| 138 |
em9va2E= |
| 139 |
=ZZZZ |
| 140 |
-----END PGP MESSAGE----- |
| 141 |
'); |
| 142 |
key | value |
| 143 |
-----+------- |
| 144 |
foo | |
| 145 |
(1 row) |
| 146 |
|
| 147 |
-- simple |
| 148 |
select * from pgp_armor_headers(' |
| 149 |
-----BEGIN PGP MESSAGE----- |
| 150 |
fookey: foovalue |
| 151 |
barkey: barvalue |
| 152 |
|
| 153 |
em9va2E= |
| 154 |
=ZZZZ |
| 155 |
-----END PGP MESSAGE----- |
| 156 |
'); |
| 157 |
key | value |
| 158 |
--------+---------- |
| 159 |
fookey | foovalue |
| 160 |
barkey | barvalue |
| 161 |
(2 rows) |
| 162 |
|
| 163 |
-- insane keys, part 1 |
| 164 |
select * from pgp_armor_headers(' |
| 165 |
-----BEGIN PGP MESSAGE----- |
| 166 |
insane:key : |
| 167 |
|
| 168 |
em9va2E= |
| 169 |
=ZZZZ |
| 170 |
-----END PGP MESSAGE----- |
| 171 |
'); |
| 172 |
key | value |
| 173 |
-------------+------- |
| 174 |
insane:key | |
| 175 |
(1 row) |
| 176 |
|
| 177 |
-- insane keys, part 2 |
| 178 |
select * from pgp_armor_headers(' |
| 179 |
-----BEGIN PGP MESSAGE----- |
| 180 |
insane:key : text value here |
| 181 |
|
| 182 |
em9va2E= |
| 183 |
=ZZZZ |
| 184 |
-----END PGP MESSAGE----- |
| 185 |
'); |
| 186 |
key | value |
| 187 |
-------------+----------------- |
| 188 |
insane:key | text value here |
| 189 |
(1 row) |
| 190 |
|
| 191 |
-- long value |
| 192 |
select * from pgp_armor_headers(' |
| 193 |
-----BEGIN PGP MESSAGE----- |
| 194 |
long: this value is more than 76 characters long, but it should still parse correctly as that''s permitted by RFC 4880 |
| 195 |
|
| 196 |
em9va2E= |
| 197 |
=ZZZZ |
| 198 |
-----END PGP MESSAGE----- |
| 199 |
'); |
| 200 |
key | value |
| 201 |
------+----------------------------------------------------------------------------------------------------------------- |
| 202 |
long | this value is more than 76 characters long, but it should still parse correctly as that's permitted by RFC 4880 |
| 203 |
(1 row) |
| 204 |
|
| 205 |
-- long value, split up |
| 206 |
select * from pgp_armor_headers(' |
| 207 |
-----BEGIN PGP MESSAGE----- |
| 208 |
long: this value is more than 76 characters long, but it should still |
| 209 |
long: parse correctly as that''s permitted by RFC 4880 |
| 210 |
|
| 211 |
em9va2E= |
| 212 |
=ZZZZ |
| 213 |
-----END PGP MESSAGE----- |
| 214 |
'); |
| 215 |
key | value |
| 216 |
------+------------------------------------------------------------------ |
| 217 |
long | this value is more than 76 characters long, but it should still |
| 218 |
long | parse correctly as that's permitted by RFC 4880 |
| 219 |
(2 rows) |
| 220 |
|
| 221 |
-- long value, split up, part 2 |
| 222 |
select * from pgp_armor_headers(' |
| 223 |
-----BEGIN PGP MESSAGE----- |
| 224 |
long: this value is more than |
| 225 |
long: 76 characters long, but it should still |
| 226 |
long: parse correctly as that''s permitted by RFC 4880 |
| 227 |
|
| 228 |
em9va2E= |
| 229 |
=ZZZZ |
| 230 |
-----END PGP MESSAGE----- |
| 231 |
'); |
| 232 |
key | value |
| 233 |
------+------------------------------------------------- |
| 234 |
long | this value is more than |
| 235 |
long | 76 characters long, but it should still |
| 236 |
long | parse correctly as that's permitted by RFC 4880 |
| 237 |
(3 rows) |
| 238 |
|
| 239 |
-- long value, split up, part 3 |
| 240 |
select * from pgp_armor_headers(' |
| 241 |
-----BEGIN PGP MESSAGE----- |
| 242 |
emptykey: |
| 243 |
long: this value is more than |
| 244 |
emptykey: |
| 245 |
long: 76 characters long, but it should still |
| 246 |
emptykey: |
| 247 |
long: parse correctly as that''s permitted by RFC 4880 |
| 248 |
emptykey: |
| 249 |
|
| 250 |
em9va2E= |
| 251 |
=ZZZZ |
| 252 |
-----END PGP MESSAGE----- |
| 253 |
'); |
| 254 |
key | value |
| 255 |
----------+------------------------------------------------- |
| 256 |
emptykey | |
| 257 |
long | this value is more than |
| 258 |
emptykey | |
| 259 |
long | 76 characters long, but it should still |
| 260 |
emptykey | |
| 261 |
long | parse correctly as that's permitted by RFC 4880 |
| 262 |
emptykey | |
| 263 |
(7 rows) |
| 264 |
|
| 265 |
select * from pgp_armor_headers(' |
| 266 |
-----BEGIN PGP MESSAGE----- |
| 267 |
Comment: dat1.blowfish.sha1.mdc.s2k3.z0 |
| 268 |
|
| 269 |
jA0EBAMCfFNwxnvodX9g0jwB4n4s26/g5VmKzVab1bX1SmwY7gvgvlWdF3jKisvS |
| 270 |
yA6Ce1QTMK3KdL2MPfamsTUSAML8huCJMwYQFfE= |
| 271 |
=JcP+ |
| 272 |
-----END PGP MESSAGE----- |
| 273 |
'); |
| 274 |
key | value |
| 275 |
---------+-------------------------------- |
| 276 |
Comment | dat1.blowfish.sha1.mdc.s2k3.z0 |
| 277 |
(1 row) |
| 278 |
|
| 279 |
-- test CR+LF line endings |
| 280 |
select * from pgp_armor_headers(replace(' |
| 281 |
-----BEGIN PGP MESSAGE----- |
| 282 |
fookey: foovalue |
| 283 |
barkey: barvalue |
| 284 |
|
| 285 |
em9va2E= |
| 286 |
=ZZZZ |
| 287 |
-----END PGP MESSAGE----- |
| 288 |
', E'\n', E'\r\n')); |
| 289 |
key | value |
| 290 |
--------+---------- |
| 291 |
fookey | foovalue |
| 292 |
barkey | barvalue |
| 293 |
(2 rows) |
| 294 |
|
| 295 |
-- test header generation |
| 296 |
select armor('zooka', array['foo'], array['bar']); |
| 297 |
armor |
| 298 |
----------------------------- |
| 299 |
-----BEGIN PGP MESSAGE-----+ |
| 300 |
foo: bar + |
| 301 |
+ |
| 302 |
em9va2E= + |
| 303 |
=D5cR + |
| 304 |
-----END PGP MESSAGE----- + |
| 305 |
|
| 306 |
(1 row) |
| 307 |
|
| 308 |
select armor('zooka', array['Version', 'Comment'], array['Created by pgcrypto', 'PostgreSQL, the world''s most advanced open source database']); |
| 309 |
armor |
| 310 |
--------------------------------------------------------------------- |
| 311 |
-----BEGIN PGP MESSAGE----- + |
| 312 |
Version: Created by pgcrypto + |
| 313 |
Comment: PostgreSQL, the world's most advanced open source database+ |
| 314 |
+ |
| 315 |
em9va2E= + |
| 316 |
=D5cR + |
| 317 |
-----END PGP MESSAGE----- + |
| 318 |
|
| 319 |
(1 row) |
| 320 |
|
| 321 |
select * from pgp_armor_headers( |
| 322 |
armor('zooka', array['Version', 'Comment'], |
| 323 |
array['Created by pgcrypto', 'PostgreSQL, the world''s most advanced open source database'])); |
| 324 |
key | value |
| 325 |
---------+------------------------------------------------------------ |
| 326 |
Version | Created by pgcrypto |
| 327 |
Comment | PostgreSQL, the world's most advanced open source database |
| 328 |
(2 rows) |
| 329 |
|
| 330 |
-- error/corner cases |
| 331 |
select armor('', array['foo'], array['too', 'many']); |
| 332 |
ERROR: mismatched array dimensions |
| 333 |
select armor('', array['too', 'many'], array['foo']); |
| 334 |
ERROR: mismatched array dimensions |
| 335 |
select armor('', array[['']], array['foo']); |
| 336 |
ERROR: wrong number of array subscripts |
| 337 |
select armor('', array['foo'], array[['']]); |
| 338 |
ERROR: wrong number of array subscripts |
| 339 |
select armor('', array[null], array['foo']); |
| 340 |
ERROR: null value not allowed for header key |
| 341 |
select armor('', array['foo'], array[null]); |
| 342 |
ERROR: null value not allowed for header value |
| 343 |
select armor('', '[0:0]={"foo"}', array['foo']); |
| 344 |
armor |
| 345 |
----------------------------- |
| 346 |
-----BEGIN PGP MESSAGE-----+ |
| 347 |
foo: foo + |
| 348 |
+ |
| 349 |
=twTO + |
| 350 |
-----END PGP MESSAGE----- + |
| 351 |
|
| 352 |
(1 row) |
| 353 |
|
| 354 |
select armor('', array['foo'], '[0:0]={"foo"}'); |
| 355 |
armor |
| 356 |
----------------------------- |
| 357 |
-----BEGIN PGP MESSAGE-----+ |
| 358 |
foo: foo + |
| 359 |
+ |
| 360 |
=twTO + |
| 361 |
-----END PGP MESSAGE----- + |
| 362 |
|
| 363 |
(1 row) |
| 364 |
|
| 365 |
select armor('', array[E'embedded\nnewline'], array['foo']); |
| 366 |
ERROR: header key must not contain newlines |
| 367 |
select armor('', array['foo'], array[E'embedded\nnewline']); |
| 368 |
ERROR: header value must not contain newlines |
| 369 |
select armor('', array['embedded: colon+space'], array['foo']); |
| 370 |
ERROR: header key must not contain ": " |