Skip to content

Commit

Permalink
Add manpages, add edgecases, fix .gitignore, remove debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkx committed Apr 2, 2021
1 parent 9476dd5 commit d877e7a
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $(TARGET_EXEC): $(SRCS)
$(CC) $(SRCS) -DBASE45_UTIL -o $@ $(LDFLAGS)

$(TARGET_TEST): $(OBJS_TEST) $(TARGET_LIB)
$(CC) $(OBJS_TEST) -o $@ $(LDFLAGS) -lbase64 -L.
$(CC) $(OBJS_TEST) -o $@ $(LDFLAGS) -lbase45 -L.

$(TARGET_LIB): $(OBJS)
ar -rcs $@ $<
Expand Down
48 changes: 48 additions & 0 deletions base45.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.Dd April 1, 2021
.Dt BASE45 1
.Os
.Sh NAME
.Nm base45
.Nd command line base45 encoder and decoder
.Sh SYNOPSIS
.Nm
.Op Fl d
.Op Ar
.Op Ar
.Sh DESCRIPTION
The
.Nm
utility will base45 encode or decode its
input
.Ar file ,
or standard input (if no file is specified) to the standard output or
to
.Ar file
if an output file is also specified. Use the
.Fl d
flag to switch to decoding.
.Pp
The base45 format is designed to match the Alphanummeric set of Mode 2
or 0010 of ISO/IEC 18004 Qr codes.
.Pp
.Sh EXAMPLES
Translate the String
.Pa Hello
into base45:
.Pp
.Dl "echo -n Hello | base45"
.Sh HISTORY
This utiltiy was developed as part of the European Health Network
their Digital Green Certificate effort during the 2020-2021 COVID19
Crisis.
.Sh BUGS
Note that this utility is designed for the relatively modests strings that
are encoded into Qr barcodes; and hence does not have a nice streaming
interface or similar.
.Sh STANDARDS
The
.Nm
utility conforms to ALPHANUMMERIC character set from section 7.44 of
ISO/EIC-18004. The actual set is 45 characters:
.Pp
.Dl 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
90 changes: 90 additions & 0 deletions base45.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
.Dd April 1, 2021
.Dt BASE45 1
.Os
.Sh NAME
.Nm base45_encode, base45_decode
.Nd conversion routines
.Sh LIBRARY
.Lb libbase45
.Sh SYNOPSIS
.In base45.h
.Ft int
.Fn base45_encode(char * dstOrNull, size_t *dst_lenOrNull, const unsigned char * src, size_t src_len);
.Ft int
.Fn base45_decode(unsigned char * dstOrNull, size_t *dst_lenOrNull, const char * src, size_t src_len);
.Sh DESCRIPTION
The base45 format is designed to match the Alphanummeric set of Mode 2
or 0010 of ISO/IEC 18004 Qr codes.
.Pp
These
.Fn base45_encode
will encode a binary buffer
.Fa src
of size
.Fa src_len
to a
.Ql \e0
terminated string. The
.Fn base45_decode
routine will decode up to
.Fa src_len
bytes from the
.Fa src
buffer back into binary. The buffer
.Fa src
does not need to be
.Ql \e0
terminated unless
.Fa src_len
is set to
.Ql 0 .
If
.Fa src_len
is set to
.Ql 0
the routine will decode the
.Fa src
until the terminating
.Ql \e0 .
.Pp
.Sh RESULTS
The results are stored in the
.Fa *dstOrNull
buffer that; with the size specified by
.Fa *dst_lenOrNull .
If the length passed is 0,
.Nm base45_encode
will assume that the buffer pointed at by
.Fa *dstOrNull .
In either case the actual decoded length of the entire string is
returned in
.Fa *dst_lenOrNull .
The terminating
.Ql \e0
added by
.Fn base45_encode
does not count for the length.
If
.Fa *dstOrNull
is
.Ql NULL
then the actual results will not be stored.
.Sh RESULTS
The functions will return a non 0 value on error. This is currently only the
case for base45_decode - when it finds an character not in the base45 set
or when the number of characters in the source is not a multiple of 2 and 3.
.Sh HISTORY
This utiltiy was developed as part of the European Health Network
their Digital Green Certificate effort during the 2020-2021 COVID19
Crisis.
.Sh BUGS
Note that this utility is designed for the relatively modests strings that
are encoded into Qr barcodes; and hence does not have a nice streaming
interface or similar.
.Sh STANDARDS
The
.Nm
utility conforms to ALPHANUMMERIC character set from section 7.44 of
ISO/EIC-18004. The actual set is 45 characters:
.Pp
.Dl 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
1 change: 0 additions & 1 deletion test.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ void check(char * in, char * out) {

assert(0 == base45_decode(dec, &dlen, out, strlen(out)));
assert(dlen == strlen(in));
for(int i = 0; i < dlen; i++) printf("%d %d %c %c %d\n", i, dec[i],dec[i],in[i],in[i]);
assert(0 == bcmp(dec,in,dlen));

printf("base64(\"%s\") -> \"%s\"\n", (char*)dec, enc);
Expand Down

0 comments on commit d877e7a

Please sign in to comment.