Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions .github/workflows/ci.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI

on:
push:
branches:
- master
- main
pull_request:

jobs:
test:
strategy:
matrix:
pg: [15, 14, 13, 12, 11, 10]
name: 🐘 PostgreSQL ${{ matrix.pg }}
runs-on: ubuntu-latest
container: pgxn/pgxn-tools
steps:
- run: pg-start ${{ matrix.pg }}
- uses: actions/checkout@v2
- run: pg-build-test

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
sha*.sql.in
sha*.sql
sha*.c
sql/hashtypes--0.1.2--0.1.3.sql
sql/hashtypes--0.1.2--0.1.3.sql
sql/*.sql.in

results/
31 changes: 22 additions & 9 deletions META.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
{
"name": "hashtypes",
"abstract": "data types for sha{1,256,512}, md5 and crc32",
"version": "0.1.4",
"maintainer": ["Chris Travers <chris.travers@adjust.com>", "Manuel Kniep <rapimo@adjust.com>"],
"license": "postgresql",
"meta-spec": {
"version": "1.0.0",
"url": "http://pgxn.org/meta/spec.txt"
},
"version": "0.1.5",
"maintainer" : [
"adjustgmbh"
],
"license": {
"PostgreSQL": "http://www.postgresql.org/about/licence"
},
"provides": {
"hashtypes": {
"file": "sql/hashtypes--0.1.4.sql",
"version": "0.1.4"
"file": "sql/hashtypes--0.1.5.sql",
"version": "0.1.5",
"abstract": "data types for sha{1,256,512}, md5 and crc32"
}
},
"meta-spec": {
"version": "1.0.0",
"url": "http://pgxn.org/meta/spec.txt"
},
"description": "data types for sha{1,256,512}, md5 and crc32",
"prereqs": {
"runtime": {
"requires": {
"PostgreSQL": "10.0.0"
}
}
},
"resources": {
"bugtracker": {
"web": "http://github.com/adjust/hashtypes/issues/"
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

HASHTYPESVERSION = 0.1.5
EXTENSION = hashtypes
DOCS = README.hashtypes
MODULE_big = hashtypes
OBJS = src/common.o src/md5.o src/crc32.o $(LN_OBJS)
DATA_built = sql/hashtypes--$(HASHTYPESVERSION).sql sql/hashtypes--0.1.2--0.1.3.sql
Expand Down
2 changes: 2 additions & 0 deletions README.hashtypes → README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![CI](https://github.com/adjust/hashtypes/actions/workflows/main.yml/badge.svg)](https://github.com/adjust/hashtypes/actions/workflows/main.yml)

This extension is actually a fork of shatypes[1] which adds some other data types
as crc32 and provides some fixes to original implementations.

Expand Down
14 changes: 14 additions & 0 deletions expected/regress_sha.out
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,17 @@ SELECT * FROM md5test_after;
5e8862cd73694287ff341e75c95e3c6a
(2 rows)

CREATE TABLE crc32test (val crc32);
INSERT INTO crc32test VALUES ('ab1'::crc32), ('ab2'::crc32);
SELECT val FROM crc32test WHERE val <> 'ab2'::crc32;
val
----------
00000ab1
(1 row)

SELECT val FROM crc32test WHERE val = 'ab2'::crc32;
val
----------
00000ab2
(1 row)

6 changes: 6 additions & 0 deletions sql/regress_sha.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ COPY md5test TO '/tmp/tst' WITH (FORMAT binary);
COPY md5test_after FROM '/tmp/tst' WITH (FORMAT binary);
SELECT * FROM md5test;
SELECT * FROM md5test_after;

CREATE TABLE crc32test (val crc32);
INSERT INTO crc32test VALUES ('ab1'::crc32), ('ab2'::crc32);

SELECT val FROM crc32test WHERE val <> 'ab2'::crc32;
SELECT val FROM crc32test WHERE val = 'ab2'::crc32;
16 changes: 7 additions & 9 deletions src/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Datum
crc32_in(PG_FUNCTION_ARGS)
{
char *in = PG_GETARG_CSTRING(0);
char *p;
long int pout;

if (strlen(in) > 8)
{
Expand All @@ -19,12 +21,9 @@ crc32_in(PG_FUNCTION_ARGS)
errmsg("crc32 value cannot exceed 32 bits")));
}

crc32 *out = palloc(sizeof(crc32));


char *p;
errno = 0;
long int pout = strtol(in, &p, 16);
pout = strtol(in, &p, 16);

if (errno != 0 || *p != 0 || p == in)
{
ereport(ERROR, (
Expand All @@ -35,17 +34,16 @@ crc32_in(PG_FUNCTION_ARGS)
/* I don't check if pout overflows uint32 because it's restricted by string
* length check above.
*/
out = (uint32_t)pout;

PG_RETURN_CRC32(out);
PG_RETURN_CRC32(pout);
}

PG_FUNCTION_INFO_V1(crc32_out);
Datum
crc32_out(PG_FUNCTION_ARGS)
{
crc32 *in = PG_GETARG_CRC32(0);
crc32 in = PG_GETARG_CRC32(0);
char *out = (char *) palloc(10);

snprintf(out, 10, "%08x", in);
PG_RETURN_CSTRING(out);
}
Expand Down
18 changes: 14 additions & 4 deletions src/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
*/
#include "postgres.h"

// pg16-compability
#ifndef SET_VARSIZE
/*
* pg >= 16 reorganized the toastable header files
* https://github.com/postgres/postgres/commit/d952373a987bad331c0e499463159dd142ced1ef
* to ensure cross version compatibility we do a bit of a hack here
*/
#include "varatt.h"
#endif

#include "access/hash.h"
#include "common.h"
#include "fmgr.h"
Expand Down Expand Up @@ -52,7 +62,7 @@ md5_in(PG_FUNCTION_ARGS)
{
char *arg = PG_GETARG_CSTRING(0);
Md5 *output;

output = (Md5 *) cstring_to_hexarr(arg, MD5_LENGTH, "MD5");

PG_RETURN_MD5(output);
Expand All @@ -63,7 +73,7 @@ Datum
md5_recv(PG_FUNCTION_ARGS)
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
Md5 *result;
Md5 *result;
int nbytes;

nbytes = buf->len - buf->cursor;
Expand All @@ -75,7 +85,7 @@ md5_recv(PG_FUNCTION_ARGS)

result = palloc(sizeof(Md5));

pq_copymsgbytes(buf, result->bytes, nbytes);
pq_copymsgbytes(buf, (char *) result->bytes, nbytes);

PG_RETURN_MD5(result);
}
Expand Down Expand Up @@ -123,7 +133,7 @@ md5_to_text(PG_FUNCTION_ARGS)

cstring = hexarr_to_cstring(value->bytes, MD5_LENGTH);
textval = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstring)));

PG_RETURN_TEXT_P(textval);
}

Expand Down