Added Base64 API to own files.
[silc.git] / lib / silcutil / silcbase64.h
diff --git a/lib/silcutil/silcbase64.h b/lib/silcutil/silcbase64.h
new file mode 100644 (file)
index 0000000..e060d4d
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+
+  silcbase64.h
+
+  Author: Pekka Riikonen <priikone@silcnet.org>
+
+  Copyright (C) 2007 Pekka Riikonen
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; version 2 of the License.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+*/
+
+/****h* silcutil/SILC Base64 API
+ *
+ * DESCRIPTION
+ *
+ * This interface provides Base64 encoding and decoding routines.
+ *
+ ***/
+
+#ifndef SILCBASE64_H
+#define SILCBASE64_H
+
+/****f* silcutil/SilcBase64API/silc_base64_encode
+ *
+ * SYNOPSIS
+ *
+ *    char *silc_base64_encode(SilcStack stack,
+ *                             unsigned char *data, SilcUInt32 len);
+ *
+ * DESCRIPTION
+ *
+ *    Encodes data into Base 64 (PEM) encoding. Returns NULL terminated
+ *    Base 64 encoded data string.
+ *
+ *    If `stack' is non-NULL the returned buffer is allocated from `stack'.
+ *
+ ***/
+char *silc_base64_encode(SilcStack stack, unsigned char *data, SilcUInt32 len);
+
+/****f* silcutil/SilcBase64API/silc_base64_encode_file
+ *
+ * SYNOPSIS
+ *
+ *    char *silc_base64_encode_file(SilcStack stack,
+ *                                  unsigned char *data, SilcUInt32 data_len);
+ *
+ * DESCRIPTION
+ *
+ *    Same as silc_base64_encode() but puts newline ('\n') every 72
+ *    characters.
+ *
+ *    If `stack' is non-NULL the returned buffer is allocated from `stack'.
+ *
+ ***/
+char *silc_base64_encode_file(SilcStack stack,
+                             unsigned char *data, SilcUInt32 data_len);
+
+/****f* silcutil/SilcBase64API/silc_base_decode
+ *
+ * SYNOPSIS
+ *
+ *    unsigned char *silc_base_decode(SilcStack stack,
+ *                                    unsigned char *base64,
+ *                                    SilcUInt32 base64_len,
+ *                                    SilcUInt32 *ret_len);
+ *
+ * DESCRIPTION
+ *
+ *    Decodes Base 64 (PEM) into data. Returns the decoded data.
+ *
+ *    If `stack' is non-NULL the returned buffer is allocated from `stack'.
+ *
+ ***/
+unsigned char *silc_base64_decode(SilcStack stack,
+                                 unsigned char *base64,
+                                 SilcUInt32 base64_len,
+                                 SilcUInt32 *ret_len);
+
+#endif /* SILCBASE64_H */