xref: /freebsd/contrib/libfido2/src/buf.c (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1 /*
2  * Copyright (c) 2018 Yubico AB. All rights reserved.
3  * Use of this source code is governed by a BSD-style
4  * license that can be found in the LICENSE file.
5  */
6 
7 #include "fido.h"
8 
9 int
10 fido_buf_read(const unsigned char **buf, size_t *len, void *dst, size_t count)
11 {
12 	if (count > *len)
13 		return (-1);
14 
15 	memcpy(dst, *buf, count);
16 	*buf += count;
17 	*len -= count;
18 
19 	return (0);
20 }
21 
22 int
23 fido_buf_write(unsigned char **buf, size_t *len, const void *src, size_t count)
24 {
25 	if (count > *len)
26 		return (-1);
27 
28 	memcpy(*buf, src, count);
29 	*buf += count;
30 	*len -= count;
31 
32 	return (0);
33 }
34