package com.yahoo.config.provision;

import ai.vespa.validation.PatternedStringWrapper;

import java.util.regex.Pattern;

/**
 * Wraps a Wireguard key.
 * For security reasons, this should only be used for public keys, although private keys use the same format.
 *
 * @author gjoranv
 */
public class WireguardKey extends PatternedStringWrapper<WireguardKey> {

    // See https://lists.zx2c4.com/pipermail/wireguard/2020-December/006222.html
    private static final Pattern pattern = Pattern.compile("^[A-Za-z0-9+/]{42}[A|E|I|M|Q|U|Y|c|g|k|o|s|w|4|8|0]=$");

    public WireguardKey(String value) {
        super(value, pattern, "Wireguard key");
    }

    public static WireguardKey from(String value) {
        return new WireguardKey(value);
    }

    @Override
    public String toString() {
        return "Wireguard key '" + value() + "'";
    }
}

@@ -520,37 +520,22 @@
 2%7D%5BA
-%7CE%7CI%7CM%7CQ%7CU%7CY%7Cc%7Cg%7Ck%7Co%7Cs%7Cw%7C4%7C8%7C
+EIMQUYcgkosw48
 0%5D=$

Fix regex