1 /* $OpenBSD: base64.c,v 1.12 2023/04/13 18:20:21 tb Exp $ */ 2 /* $OpenBSD: base64.c,v 1.12 2023/04/13 18:20:21 tb Exp $ */ 3 /* 4 * The author of this code is Angelos D. Keromytis (angelos@dsl.cis.upenn.edu) 5 * 6 * This code was written by Angelos D. Keromytis in Philadelphia, PA, USA, 7 * in April-May 1998 8 * 9 * Copyright (C) 1998, 1999 by Angelos D. Keromytis. 10 * 11 * Permission to use, copy, and modify this software with or without fee 12 * is hereby granted, provided that this entire notice is included in 13 * all copies of any software which is or includes a copy or 14 * modification of this software. 15 * 16 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTY. IN PARTICULAR, THE AUTHORS MAKES NO 18 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE 19 * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR 20 * PURPOSE. 21 */ 22 23 #include <sys/types.h> 24 25 #include <ctype.h> 26 #include <regex.h> 27 #include <stdio.h> 28 #include <stdlib.h> 29 #include <string.h> 30 31 #include "keynote.h" 32 33 int __b64_ntop(unsigned char const *, size_t, char *, size_t); 34 int __b64_pton(char const *, unsigned char *, size_t); 35 36 int 37 kn_encode_base64(unsigned char const *src, unsigned int srclength, char *target, 38 unsigned int targsize) 39 { 40 int i; 41 42 i = __b64_ntop(src, srclength, target, targsize); 43 if (i == -1) 44 keynote_errno = ERROR_SYNTAX; 45 return i; 46 } 47 48 int 49 kn_decode_base64(char const *src, unsigned char *target, unsigned int targsize) 50 { 51 int i; 52 53 i = __b64_pton(src, target, targsize); 54 if (i == -1) 55 keynote_errno = ERROR_SYNTAX; 56 return i; 57 } 58