Skip to content

Commit 430675f

Browse files
committed
feat: encrypted_hmac_256_operator class
1 parent 2905a33 commit 430675f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/operators/operator_class.sql

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,45 @@ CREATE OPERATOR CLASS eql_v2.encrypted_operator DEFAULT FOR TYPE eql_v2_encrypte
4848
OPERATOR 5 >,
4949
FUNCTION 1 eql_v2.compare(a eql_v2_encrypted, b eql_v2_encrypted);
5050

51+
52+
--------------------
53+
54+
55+
CREATE FUNCTION eql_v2.compare_hmac(a eql_v2_encrypted, b eql_v2_encrypted)
56+
RETURNS integer
57+
IMMUTABLE STRICT PARALLEL SAFE
58+
AS $$
59+
DECLARE
60+
a_hmac eql_v2.hmac_256;
61+
b_hmac eql_v2.hmac_256;
62+
BEGIN
63+
64+
a_hmac = eql_v2.hmac_256(a);
65+
b_hmac = eql_v2.hmac_256(b);
66+
67+
IF a_hmac = b_hmac THEN
68+
RETURN 0;
69+
END IF;
70+
71+
IF a_hmac < b_hmac THEN
72+
RETURN -1;
73+
END IF;
74+
75+
IF a_hmac > b_hmac THEN
76+
RETURN 1;
77+
END IF;
78+
79+
END;
80+
$$ LANGUAGE plpgsql;
81+
82+
83+
CREATE OPERATOR FAMILY eql_v2.encrypted_hmac_256_operator USING btree;
84+
85+
CREATE OPERATOR CLASS eql_v2.encrypted_hmac_256_operator FOR TYPE eql_v2_encrypted USING btree FAMILY eql_v2.encrypted_hmac_256_operator AS
86+
OPERATOR 1 <,
87+
OPERATOR 2 <=,
88+
OPERATOR 3 =,
89+
OPERATOR 4 >=,
90+
OPERATOR 5 >,
91+
FUNCTION 1 eql_v2.compare_hmac(a eql_v2_encrypted, b eql_v2_encrypted);
92+

0 commit comments

Comments
 (0)