Debian Codegraph @

contrib/pgcrypto/expected/pgp-compression.out

raw
1 --
2 -- PGP compression support
3 --
4 select pgp_sym_decrypt(dearmor('
5 -----BEGIN PGP MESSAGE-----
6
7 ww0ECQMCsci6AdHnELlh0kQB4jFcVwHMJg0Bulop7m3Mi36s15TAhBo0AnzIrRFrdLVCkKohsS6+
8 DMcmR53SXfLoDJOv/M8uKj3QSq7oWNIp95pxfA==
9 =tbSn
10 -----END PGP MESSAGE-----
11 '), 'key', 'expect-compress-algo=1');
12 pgp_sym_decrypt
13 -----------------
14 Secret message
15 (1 row)
16
17 select pgp_sym_decrypt(
18 pgp_sym_encrypt('Secret message', 'key', 'compress-algo=0'),
19 'key', 'expect-compress-algo=0');
20 pgp_sym_decrypt
21 -----------------
22 Secret message
23 (1 row)
24
25 select pgp_sym_decrypt(
26 pgp_sym_encrypt('Secret message', 'key', 'compress-algo=1'),
27 'key', 'expect-compress-algo=1');
28 pgp_sym_decrypt
29 -----------------
30 Secret message
31 (1 row)
32
33 select pgp_sym_decrypt(
34 pgp_sym_encrypt('Secret message', 'key', 'compress-algo=2'),
35 'key', 'expect-compress-algo=2');
36 pgp_sym_decrypt
37 -----------------
38 Secret message
39 (1 row)
40
41 -- level=0 should turn compression off
42 select pgp_sym_decrypt(
43 pgp_sym_encrypt('Secret message', 'key',
44 'compress-algo=2, compress-level=0'),
45 'key', 'expect-compress-algo=0');
46 pgp_sym_decrypt
47 -----------------
48 Secret message
49 (1 row)
50
51 -- check corner case involving an input string of 16kB, as per bug #16476.
52 SELECT setseed(0);
53 setseed
54 ---------
55
56 (1 row)
57
58 WITH random_string AS
59 (
60 -- This generates a random string of 16366 bytes. This is chosen
61 -- as random so that it does not get compressed, and the decompression
62 -- would work on a string with the same length as the origin, making the
63 -- test behavior more predictable. lpad() ensures that the generated
64 -- hexadecimal value is completed by extra zero characters if random()
65 -- has generated a value strictly lower than 16.
66 SELECT string_agg(decode(lpad(to_hex((random()*256)::int), 2, '0'), 'hex'), '') as bytes
67 FROM generate_series(0, 16365)
68 )
69 SELECT bytes =
70 pgp_sym_decrypt_bytea(
71 pgp_sym_encrypt_bytea(bytes, 'key',
72 'compress-algo=1,compress-level=1'),
73 'key', 'expect-compress-algo=1')
74 AS is_same
75 FROM random_string;
76 is_same
77 ---------
78 t
79 (1 row)
80