summaryrefslogtreecommitdiffstats
path: root/lib/libfido2/src/buf.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libfido2/src/buf.c')
-rw-r--r--lib/libfido2/src/buf.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/libfido2/src/buf.c b/lib/libfido2/src/buf.c
new file mode 100644
index 00000000000..67ff95a2d36
--- /dev/null
+++ b/lib/libfido2/src/buf.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2018 Yubico AB. All rights reserved.
+ * Use of this source code is governed by a BSD-style
+ * license that can be found in the LICENSE file.
+ */
+
+#include <string.h>
+#include "fido.h"
+
+int
+buf_read(const unsigned char **buf, size_t *len, void *dst, size_t count)
+{
+ if (count > *len)
+ return (-1);
+
+ memcpy(dst, *buf, count);
+ *buf += count;
+ *len -= count;
+
+ return (0);
+}
+
+int
+buf_write(unsigned char **buf, size_t *len, const void *src, size_t count)
+{
+ if (count > *len)
+ return (-1);
+
+ memcpy(*buf, src, count);
+ *buf += count;
+ *len -= count;
+
+ return (0);
+}