fix: hashed_text and email are text newtypes

This commit is contained in:
Orion Kindel 2023-06-10 13:02:20 -05:00
parent 7a4d728337
commit c19a46b736
Signed by untrusted user who does not match committer: orion
GPG Key ID: 6D4165AE4C928719
2 changed files with 4 additions and 10 deletions

View File

@ -1 +1 @@
create type public.email as (email text); select create_newtype_text('public.email');

View File

@ -1,10 +1,4 @@
create type hashed_text as (hashed text); select create_newtype_text('public.hashed_text');
create function hashed_text_string(hashed hashed_text)
returns text
language sql
immutable
as 'select (hashed.hashed);';
create function hash_text(plain text) create function hash_text(plain text)
returns hashed_text returns hashed_text
@ -12,7 +6,7 @@ create function hash_text(plain text)
immutable immutable
as $$ as $$
begin begin
return row(crypt(plain, gen_salt('bf'))); return hashed_text_of_string(crypt(plain, gen_salt('bf')));
end; end;
$$; $$;
@ -22,6 +16,6 @@ create function hashed_text_matches(plain text, hashed hashed_text)
immutable immutable
as $$ as $$
begin begin
return hashed_text_string(hashed) = crypt(plain, hashed_text_string(hashed)); return hashed_text_to_string(hashed) = crypt(plain, hashed_text_to_string(hashed));
end; end;
$$; $$;