OBJ = md5.o sha1.o rng.o internal.o
CC=gcc
+CFLAGS=-Wall -I. -L.
# set the following for windows
#LDFLAGS += -liphlpapi
-all: uuidgen
+all: libpduuid.a
windows: libpduuid.a uuidgen.o
- gcc $(CFLAGS) -Wall -L. -o $@ uuidgen.o -lpduuid $(LDFLAGS) -liphlpapi
+ $(CC) $(CFLAGS) -Wall -L. -o $@ uuidgen.o -lpduuid $(LDFLAGS) -liphlpapi
libpduuid.a: $(OBJ)
ar rcuv $@ $+
ranlib $@
+t/%.t: t/%.o t/ctap.o
+ $(CC) $(CFLAGS) -lpduuid -Wall -I. -o $@ $+
+
+test: t/uuidgen.t libpduuid.a
+ prove t/*.t
+
md5.o: md5.c
- gcc $(CFLAGS) -Wall -fPIC -DLTC_SMALL_CODE -c -o $@ $+
+ $(CC) $(CFLAGS) -Wall -fPIC -DLTC_SMALL_CODE -c -o $@ $+
sha1.o: sha1.c
- gcc $(CFLAGS) -Wall -fPIC -DLTC_SMALL_CODE -c -o $@ $+
+ $(CC) $(CFLAGS) -Wall -fPIC -DLTC_SMALL_CODE -c -o $@ $+
rng.o: rng.c
- gcc $(CFLAGS) -Wall -fPIC -c -o $@ $+
+ $(CC) $(CFLAGS) -Wall -fPIC -c -o $@ $+
internal.o: internal.c
- gcc $(CFLAGS) -Wall -fPIC -c -o $@ $+
+ $(CC) $(CFLAGS) -Wall -fPIC -c -o $@ $+
uuidgen: libpduuid.a uuidgen.o
- gcc $(CFLAGS) -Wall -L. -o $@ uuidgen.o -lpduuid $(LDFLAGS)
+ $(CC) $(CFLAGS) -Wall -L. -o $@ uuidgen.o -lpduuid $(LDFLAGS)
clean:
rm -f *.o *.a uuidgen postgres/*.o postgres/*.so
continue;
}
if (ioctl(s, SIOCGIFHWADDR, req) == 0) {
+ int j;
data = (unsigned char *)req->ifr_hwaddr.sa_data;
node = data[0];
node = node << 8; node += data[1];
}
return 1;
}
+
+/* pre-defined namespace uuids */
+
+pd_uuid_t pd_uuid_ns_dns = {
+ {
+ 0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1,
+ 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8
+ }
+};
+
+pd_uuid_t pd_uuid_ns_url = {
+ {
+ 0x6b, 0xa7, 0xb8, 0x11, 0x9d, 0xad, 0x11, 0xd1,
+ 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8
+ }
+};
+
+pd_uuid_t pd_uuid_ns_oid = {
+ {
+ 0x6b, 0xa7, 0xb8, 0x12, 0x9d, 0xad, 0x11, 0xd1,
+ 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8
+ }
+};
+
+pd_uuid_t pd_uuid_ns_x500 = {
+ {
+ 0x6b, 0xa7, 0xb8, 0x14, 0x9d, 0xad, 0x11, 0xd1,
+ 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8
+ }
+};
+
+int pd_uuid_copy(pd_uuid_t *src, pd_uuid_t *dst) {
+ if (src && dst) {
+ memcpy(dst->data, src->data, 16);
+ return 1;
+ }
+ return 0;
+}
+
+int pd_uuid_cmp(pd_uuid_t *a, pd_uuid_t *b) {
+ if (a && b) {
+ return memcmp(a, b, 16);
+ }
+ return 1;
+}
int pd_uuid_make_v3(struct pd_uuid_state *s, pd_uuid_t *uuid, pd_uuid_t *ns, void *data, int len);
int pd_uuid_make_v5(struct pd_uuid_state *s, pd_uuid_t *uuid, pd_uuid_t *ns, void *data, int len);
+int pd_uuid_copy(pd_uuid_t *src, pd_uuid_t *dst);
+int pd_uuid_cmp(pd_uuid_t *a, pd_uuid_t *b);
+
int pd_set_uuid_hash(pd_uuid_t *s, void *hash, int version);
int pd_uuid_set_string(pd_uuid_t *uuid, char *s);
unsigned long pd_uuid_rng_get_bytes(unsigned char *out, unsigned long outlen);
+pd_uuid_t pd_uuid_ns_x500;
+pd_uuid_t pd_uuid_ns_url;
+pd_uuid_t pd_uuid_ns_dns;
+pd_uuid_t pd_uuid_ns_oid;
#endif
+++ /dev/null
-/*
- * test program for uuid library
- *
- * written by nathan wagner and placed in the public domain
- */
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "pduuid.h"
-
-void ufmt(pd_uuid_t *uuid, char *s) {
- int i;
- for (i=0;i<4;i++) {
- s += sprintf(s, "%02x", uuid->data[i]);
- }
- s += sprintf(s, "-");
- for (;i<6;i++) {
- s += sprintf(s, "%02x", uuid->data[i]);
- }
- s += sprintf(s, "-");
- for (;i<8;i++) {
- s += sprintf(s, "%02x", uuid->data[i]);
- }
- s += sprintf(s, "-");
- for (;i<10;i++) {
- s += sprintf(s, "%02x", uuid->data[i]);
- }
- s += sprintf(s, "-");
- for (;i<16;i++) {
- s += sprintf(s, "%02x", uuid->data[i]);
- }
-}
-
-int main(int ac, char *av[]) {
- pd_uuid_t uuid;
- pd_uuid_t dns;
- char fmt[37];
-
-#ifdef WIN32
- srand(time(0));
-#else
- srandom(time(0));
-#endif
-
- pd_uuid_make_v1(0, &uuid);
- ufmt(&uuid, fmt);
- printf("v1: %s\n", fmt);
-
- pd_uuid_make_v4(0, &uuid);
- ufmt(&uuid, fmt);
- printf("v4: %s\n", fmt);
-
- pd_uuid_set_string(&dns, "6ba7b810-9dad-11d1-80b4-00c04fd430c8");
- ufmt(&dns, fmt);
- printf("dns: %s\n", fmt);
-
- pd_uuid_make_v3(0, &uuid, &dns, "granicus.if.org", strlen("granicus.if.org"));
- ufmt(&uuid, fmt);
- printf("granicus.if.org (v3): %s\n", fmt);
-
- pd_uuid_make_v5(0, &uuid, &dns, "granicus.if.org", strlen("granicus.if.org"));
- ufmt(&uuid, fmt);
- printf("granicus.if.org (v5): %s\n", fmt);
-
- return 0;
-}