|
| 1 | +CREATE OR REPLACE FUNCTION pgsodium.crypto_sign_update_agg1(state bytea, message bytea) |
| 2 | + RETURNS bytea |
| 3 | +AS |
| 4 | +$$ |
| 5 | + SELECT pgsodium.crypto_sign_update(COALESCE(state, pgsodium.crypto_sign_init()), message); |
| 6 | +$$ |
| 7 | +LANGUAGE SQL IMMUTABLE; |
| 8 | + |
| 9 | +COMMENT ON FUNCTION pgsodium.crypto_sign_update_agg1(bytea, bytea) IS |
| 10 | +'Internal helper function for crypto_sign_update_agg(bytea). This |
| 11 | +initializes state if it has not already been initialized.'; |
| 12 | + |
| 13 | +CREATE OR REPLACE FUNCTION pgsodium.crypto_sign_update_agg2(cur_state bytea, |
| 14 | + initial_state bytea, |
| 15 | + message bytea) |
| 16 | + RETURNS bytea |
| 17 | +as |
| 18 | +$$ |
| 19 | + SELECT pgsodium.crypto_sign_update( |
| 20 | + COALESCE(cur_state, initial_state), |
| 21 | + message) |
| 22 | +$$ |
| 23 | +LANGUAGE SQL IMMUTABLE; |
| 24 | + |
| 25 | +COMMENT ON FUNCTION pgsodium.crypto_sign_update_agg2(bytea, bytea, bytea) IS |
| 26 | +'Internal helper function for crypto_sign_update_agg(bytea, bytea). This |
| 27 | +initializes state to the state passed to the aggregate as a parameter, |
| 28 | +if it has not already been initialized.'; |
| 29 | + |
| 30 | +CREATE OR REPLACE AGGREGATE pgsodium.crypto_sign_update_agg(message bytea) |
| 31 | + ( |
| 32 | + SFUNC = pgsodium.crypto_sign_update_agg1, |
| 33 | + STYPE = bytea, |
| 34 | + PARALLEL = unsafe); |
| 35 | + |
| 36 | +COMMENT ON AGGREGATE pgsodium.crypto_sign_update_agg(bytea) IS |
| 37 | +'Multi-part message signing aggregate that returns a state which can |
| 38 | +then be finalised using crypto_sign_final() or to which other parts |
| 39 | +can be added crypto_sign_update() or another message signing aggregate |
| 40 | +function. |
| 41 | +
|
| 42 | +Note that when signing mutli-part messages using aggregates, the order |
| 43 | +in which message parts is processed is critical. You *must* ensure |
| 44 | +that the order of messages passed to the aggregate is invariant.'; |
| 45 | + |
| 46 | +CREATE OR REPLACE AGGREGATE pgsodium.crypto_sign_update_agg(state bytea, message bytea) |
| 47 | + ( |
| 48 | + SFUNC = pgsodium.crypto_sign_update_agg2, |
| 49 | + STYPE = bytea, |
| 50 | + PARALLEL = unsafe); |
| 51 | + |
| 52 | +COMMENT ON AGGREGATE pgsodium.crypto_sign_update_agg(bytea, bytea) IS |
| 53 | +'Multi-part message signing aggregate that returns a state which can |
| 54 | +then be finalised using crypto_sign_final() or to which other parts |
| 55 | +can be added crypto_sign_update() or another message signing aggregate |
| 56 | +function. |
| 57 | +
|
| 58 | +The first argument to this aggregate is the input state. This may be |
| 59 | +the result of a previous crypto_sign_update_agg(), a previous |
| 60 | +crypto_sign_update(). |
| 61 | +
|
| 62 | +Note that when signing mutli-part messages using aggregates, the order |
| 63 | +in which message parts is processed is critical. You *must* ensure |
| 64 | +that the order of messages passed to the aggregate is invariant.'; |
| 65 | + |
0 commit comments