Files
gamertan bfe6cfd29e
verify / verify (push) Successful in 3m40s
auth: publish passkey foundations preview
2026-08-21 17:33:00 -04:00

82 lines
3.4 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package protocol
// isISO3166Alpha2 reports whether code is a valid ISO 3166-1 alpha-2 country code.
// Officially-assigned codes and user-assigned codes (AA, QMQZ, XAXZ, ZZ) are both
// accepted; the W3C WebAuthn test vectors use AA, so rejecting user-assigned codes
// would fail §16 conformance. Codes of the wrong length, wrong case, or containing
// non-letters are rejected.
func isISO3166Alpha2(code string) bool {
if _, ok := iso3166Alpha2Codes[code]; ok {
return true
}
return isISO3166Alpha2UserAssigned(code)
}
// isISO3166Alpha2UserAssigned reports whether code is a user-assignable code per
// ISO 3166-1 (AA, QMQZ, XAXZ, ZZ).
func isISO3166Alpha2UserAssigned(code string) bool {
if len(code) != 2 {
return false
}
switch code {
case "AA", "ZZ":
return true
}
switch code[0] {
case 'Q':
return code[1] >= 'M' && code[1] <= 'Z'
case 'X':
return code[1] >= 'A' && code[1] <= 'Z'
}
return false
}
var iso3166Alpha2Codes = map[string]struct{}{
"AD": {}, "AE": {}, "AF": {}, "AG": {}, "AI": {}, "AL": {}, "AM": {}, "AO": {},
"AQ": {}, "AR": {}, "AS": {}, "AT": {}, "AU": {}, "AW": {}, "AX": {}, "AZ": {},
"BA": {}, "BB": {}, "BD": {}, "BE": {}, "BF": {}, "BG": {}, "BH": {}, "BI": {},
"BJ": {}, "BL": {}, "BM": {}, "BN": {}, "BO": {}, "BQ": {}, "BR": {}, "BS": {},
"BT": {}, "BV": {}, "BW": {}, "BY": {}, "BZ": {},
"CA": {}, "CC": {}, "CD": {}, "CF": {}, "CG": {}, "CH": {}, "CI": {}, "CK": {},
"CL": {}, "CM": {}, "CN": {}, "CO": {}, "CR": {}, "CU": {}, "CV": {}, "CW": {},
"CX": {}, "CY": {}, "CZ": {},
"DE": {}, "DJ": {}, "DK": {}, "DM": {}, "DO": {}, "DZ": {},
"EC": {}, "EE": {}, "EG": {}, "EH": {}, "ER": {}, "ES": {}, "ET": {},
"FI": {}, "FJ": {}, "FK": {}, "FM": {}, "FO": {}, "FR": {},
"GA": {}, "GB": {}, "GD": {}, "GE": {}, "GF": {}, "GG": {}, "GH": {}, "GI": {},
"GL": {}, "GM": {}, "GN": {}, "GP": {}, "GQ": {}, "GR": {}, "GS": {}, "GT": {},
"GU": {}, "GW": {}, "GY": {},
"HK": {}, "HM": {}, "HN": {}, "HR": {}, "HT": {}, "HU": {},
"ID": {}, "IE": {}, "IL": {}, "IM": {}, "IN": {}, "IO": {}, "IQ": {}, "IR": {},
"IS": {}, "IT": {},
"JE": {}, "JM": {}, "JO": {}, "JP": {},
"KE": {}, "KG": {}, "KH": {}, "KI": {}, "KM": {}, "KN": {}, "KP": {}, "KR": {},
"KW": {}, "KY": {}, "KZ": {},
"LA": {}, "LB": {}, "LC": {}, "LI": {}, "LK": {}, "LR": {}, "LS": {}, "LT": {},
"LU": {}, "LV": {}, "LY": {},
"MA": {}, "MC": {}, "MD": {}, "ME": {}, "MF": {}, "MG": {}, "MH": {}, "MK": {},
"ML": {}, "MM": {}, "MN": {}, "MO": {}, "MP": {}, "MQ": {}, "MR": {}, "MS": {},
"MT": {}, "MU": {}, "MV": {}, "MW": {}, "MX": {}, "MY": {}, "MZ": {},
"NA": {}, "NC": {}, "NE": {}, "NF": {}, "NG": {}, "NI": {}, "NL": {}, "NO": {},
"NP": {}, "NR": {}, "NU": {}, "NZ": {},
"OM": {},
"PA": {}, "PE": {}, "PF": {}, "PG": {}, "PH": {}, "PK": {}, "PL": {}, "PM": {},
"PN": {}, "PR": {}, "PS": {}, "PT": {}, "PW": {}, "PY": {},
"QA": {},
"RE": {}, "RO": {}, "RS": {}, "RU": {}, "RW": {},
"SA": {}, "SB": {}, "SC": {}, "SD": {}, "SE": {}, "SG": {}, "SH": {}, "SI": {},
"SJ": {}, "SK": {}, "SL": {}, "SM": {}, "SN": {}, "SO": {}, "SR": {}, "SS": {},
"ST": {}, "SV": {}, "SX": {}, "SY": {}, "SZ": {},
"TC": {}, "TD": {}, "TF": {}, "TG": {}, "TH": {}, "TJ": {}, "TK": {}, "TL": {},
"TM": {}, "TN": {}, "TO": {}, "TR": {}, "TT": {}, "TV": {}, "TW": {}, "TZ": {},
"UA": {}, "UG": {}, "UM": {}, "US": {}, "UY": {}, "UZ": {},
"VA": {}, "VC": {}, "VE": {}, "VG": {}, "VI": {}, "VN": {}, "VU": {},
"WF": {}, "WS": {},
"YE": {}, "YT": {},
"ZA": {}, "ZM": {}, "ZW": {},
}