package tofuproxy

import "unicode/utf8"

// Copy-pasted from crypto/x509, as it is not public.
func toLowerCaseASCII(in string) string {
	isAlreadyLowerCase := true
	for _, c := range in {
		if c == utf8.RuneError {
			isAlreadyLowerCase = false
			break
		}
		if 'A' <= c && c <= 'Z' {
			isAlreadyLowerCase = false
			break
		}
	}
	if isAlreadyLowerCase {
		return in
	}
	out := []byte(in)
	for i, c := range out {
		if 'A' <= c && c <= 'Z' {
			out[i] += 'a' - 'A'
		}
	}
	return string(out)
}
