X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=libeap%2Fsrc%2Futils%2Fwpabuf.c;h=96cb25cc1764b5be4095067b88a90eea9eada1d4;hb=d1dd9aae6741e74f20bfc35e1db598652680279d;hp=11e7323619de8b2131e51ce00afb08c864f92582;hpb=4f319dde67a76fe0aaf33f6d2788968012584ada;p=mech_eap.git diff --git a/libeap/src/utils/wpabuf.c b/libeap/src/utils/wpabuf.c index 11e7323..96cb25c 100644 --- a/libeap/src/utils/wpabuf.c +++ b/libeap/src/utils/wpabuf.c @@ -310,3 +310,33 @@ void wpabuf_printf(struct wpabuf *buf, char *fmt, ...) wpabuf_overflow(buf, res); buf->used += res; } + + +/** + * wpabuf_parse_bin - Parse a null terminated string of binary data to a wpabuf + * @buf: Buffer with null terminated string (hexdump) of binary data + * Returns: wpabuf or %NULL on failure + * + * The string len must be a multiple of two and contain only hexadecimal digits. + */ +struct wpabuf * wpabuf_parse_bin(const char *buf) +{ + size_t len; + struct wpabuf *ret; + + len = os_strlen(buf); + if (len & 0x01) + return NULL; + len /= 2; + + ret = wpabuf_alloc(len); + if (ret == NULL) + return NULL; + + if (hexstr2bin(buf, wpabuf_put(ret, len), len)) { + wpabuf_free(ret); + return NULL; + } + + return ret; +}