diff options
-rw-r--r-- | lib/tunnel_encaps.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/tunnel_encaps.c b/lib/tunnel_encaps.c index aa3e6b29..590cf958 100644 --- a/lib/tunnel_encaps.c +++ b/lib/tunnel_encaps.c @@ -269,13 +269,21 @@ int format_tunnel_encap(const eattr *a, byte *buf, uint size) return pos - buf; ADVANCE(pos, size, l); - for (uint i = 0; i < encap.encap_len; i++) { - if (size < 4) { - return pos - buf; - } + if (encap.encap_len == sizeof(wg_key)) { + wg_key_b64_string base64; + wg_key_to_base64(base64, encap.encap); - l = bsprintf(pos, "%02x ", data[i]); + l = bsnprintf(pos, size, "%s", base64); ADVANCE(pos, size, l); + } else { + for (uint i = 0; i < encap.encap_len; i++) { + if (size < 4) { + return pos - buf; + } + + l = bsnprintf(pos, size, "%02x ", data[i]); + ADVANCE(pos, size, l); + } } } |