// parseMAC48s returns a slice of uint64 MAC addresses.
186628
func parseMAC48s(macs []string) ([]uint64, error) {
	mac48s := make([]uint64, len(macs))
	for i, mac := range macs {
		mac48, err := common.ParseMAC48(mac)
		if err != nil {
			return nil, status.Errorf(codes.InvalidArgument, "invalid MAC-48 address %q", mac)
		}
		mac48s[i] = uint64(mac48)
	}
	return mac48s, nil
}
408262
func ParseBytes(b []byte) (UUID, error) {
	gu, err := guuid.ParseBytes(b)
	if err == nil {
		return gu[:], nil
	}
	return nil, err
}
959743
func parseMount(ss []string) (*Mount, error) {
	if len(ss) < deviceEntryLen {
		return nil, fmt.Errorf("invalid device entry: %v", ss)
	}

	// Check for specific words appearing at specific indices to ensure
	// the format is consistent with what we expect
	format := []struct {
		i int
		s string
	}{
		{i: 0, s: "device"},
		{i: 2, s: "mounted"},
		{i: 3, s: "on"},
		{i: 5, s: "with"},
		{i: 6, s: "fstype"},
	}

	for _, f := range format {
		if ss[f.i] != f.s {
			return nil, fmt.Errorf("invalid device entry: %v", ss)
		}
	}

	return &Mount{
		Device: ss[1],
		Mount:  ss[4],
		Type:   ss[7],
	}, nil
}
1103865
func (k *Key) ValidUint64s(delim string) []uint64 {
	vals, _ := k.parseUint64s(k.Strings(delim), false, false)
	return vals
}
286395
func ParseMAC(s string) (MAC, error) {
	ha, err := net.ParseMAC(s)
	if err != nil {
		return MAC{}, err
	}
	if len(ha) != 6 {
		return MAC{}, fmt.Errorf("invalid MAC address %s", s)
	}

	return MAC(ha), nil
}
134010
func parseSeccompArgs(patchSeccompMode string, patchSeccompSet string) (*types.Isolator, error) {
	// Parse mode flag and additional keyed arguments.
	var errno, mode string
	args := strings.Split(patchSeccompMode, ",")
	for _, a := range args {
		kv := strings.Split(a, "=")
		switch len(kv) {
		case 1:
			// mode, either "remove" or "retain"
			mode = kv[0]
		case 2:
			// k=v argument, only "errno" allowed for now
			if kv[0] == "errno" {
				errno = kv[1]
			} else {
				return nil, fmt.Errorf("invalid seccomp-mode optional argument: %s", a)
			}
		default:
			return nil, fmt.Errorf("cannot parse seccomp-mode argument: %s", a)
		}
	}

	// Instantiate an Isolator with the content specified by the --seccomp-set parameter.
	var err error
	var seccomp types.AsIsolator
	switch mode {
	case "remove":
		seccomp, err = types.NewLinuxSeccompRemoveSet(errno, strings.Split(patchSeccompSet, ",")...)
	case "retain":
		seccomp, err = types.NewLinuxSeccompRetainSet(errno, strings.Split(patchSeccompSet, ",")...)
	default:
		err = fmt.Errorf("unknown seccomp mode %s", mode)
	}
	if err != nil {
		return nil, fmt.Errorf("cannot parse seccomp isolator: %s", err)
	}
	seccompIsolator, err := seccomp.AsIsolator()
	if err != nil {
		return nil, err
	}
	return seccompIsolator, nil
}
1067410
func ParseBewit(bewit string) (*Auth, error) {
	if len(bewit)%4 != 0 {
		bewit += strings.Repeat("=", 4-len(bewit)%4)
	}
	decoded, err := base64.URLEncoding.DecodeString(bewit)
	if err != nil {
		return nil, AuthFormatError{"bewit", "malformed base64 encoding"}
	}
	components := bytes.SplitN(decoded, []byte(`\`), 4)
	if len(components) != 4 {
		return nil, AuthFormatError{"bewit", "missing components"}
	}

	auth := &Auth{
		Credentials:     Credentials{ID: string(components[0])},
		Ext:             string(components[3]),
		Method:          "GET",
		ActualTimestamp: Now(),
		IsBewit:         true,
	}

	ts, err := strconv.ParseInt(string(components[1]), 10, 64)
	if err != nil {
		return nil, AuthFormatError{"ts", "not an integer"}
	}
	auth.Timestamp = time.Unix(ts, 0)

	auth.MAC = make([]byte, base64.StdEncoding.DecodedLen(len(components[2])))
	n, err := base64.StdEncoding.Decode(auth.MAC, components[2])
	if err != nil {
		return nil, AuthFormatError{"mac", "malformed base64 encoding"}
	}
	auth.MAC = auth.MAC[:n]

	return auth, nil
}
40931
func (m MAC) Uint64() (uint64, error) {
	if len(m) != 6 {
		return 0, fmt.Errorf("Invalid MAC address %s", m.String())
	}

	return uint64(m[5])<<40 | uint64(m[4])<<32 | uint64(m[3])<<24 |
		uint64(m[2])<<16 | uint64(m[1])<<8 | uint64(m[0]), nil
}
1271829
func validMacAddress(macaddr string) error {
	if _, err := net.ParseMAC(macaddr); err != nil {
		return fmt.Errorf("Can not parse MAC address: %s", err)
	}

	if _, err := FindInterfaceByMacAddress(macaddr); err == nil {
		return fmt.Errorf("MAC Address already assigned on the host: %s", macaddr)
	}

	return nil
}
2328
func ParseCiphers(tlsConfig *config.TLSConfig) ([]uint16, error) {
	suites := []uint16{}

	cipherStr := strings.TrimSpace(tlsConfig.TLSCipherSuites)

	var parsedCiphers []string
	if cipherStr == "" {
		parsedCiphers = defaultTLSCiphers

	} else {
		parsedCiphers = strings.Split(tlsConfig.TLSCipherSuites, ",")
	}
	for _, cipher := range parsedCiphers {
		c, ok := supportedTLSCiphers[cipher]
		if !ok {
			return suites, fmt.Errorf("unsupported TLS cipher %q", cipher)
		}
		suites = append(suites, c)
	}

	// Ensure that the specified cipher suite list is supported by the TLS
	// Certificate signature algorithm. This is a check for user error, where a
	// TLS certificate could support RSA but a user has configured a cipher suite
	// list of ciphers where only ECDSA is supported.
	keyLoader := tlsConfig.GetKeyLoader()

	// Ensure that the keypair has been loaded before continuing
	keyLoader.LoadKeyPair(tlsConfig.CertFile, tlsConfig.KeyFile)

	if keyLoader.GetCertificate() != nil {
		supportedSignatureAlgorithm, err := getSignatureAlgorithm(keyLoader.GetCertificate())
		if err != nil {
			return []uint16{}, err
		}

		for _, cipher := range parsedCiphers {
			if supportedCipherSignatures[cipher] == supportedSignatureAlgorithm {
				// Positive case, return the matched cipher suites as the signature
				// algorithm is also supported
				return suites, nil
			}
		}

		// Negative case, if this is reached it means that none of the specified
		// cipher suites signature algorithms match the signature algorithm
		// for the certificate.
		return []uint16{}, fmt.Errorf("Specified cipher suites don't support the certificate signature algorithm %s, consider adding more cipher suites to match this signature algorithm.", supportedSignatureAlgorithm)
	}

	// Default in case this function is called but TLS is not actually configured
	// This is only reached if the TLS certificate is nil
	return []uint16{}, nil
}
683979
func macAddress() []byte {
	address := [6]byte{}
	ifaces, err := net.Interfaces()
	// Try to get address from interfaces.
	if err == nil {
		set := false
		for _, iface := range ifaces {
			if len(iface.HardwareAddr.String()) != 0 {
				copy(address[:], []byte(iface.HardwareAddr))
				set = true
				break
			}
		}
		if set {
			// Had success.
			return address[:]
		}
	}
	// Need a random address.
	rand.Read(address[:])
	address[0] |= 0x01
	return address[:]
}
703143
func parseSeqNumber(v string) (uint32, error) {
	if n, err := strconv.ParseUint(v, 10, 32); err == nil && v[0] != '0' {
		return uint32(n), nil
	} else if v == "*" {
		return 0, nil
	}
	return 0, ErrBadSeqSet(v)
}
1265685
func parseMacroToken(p *parser, t *token) (string, error) {
	return parseMacro(p, t.value)
}
307838
func (mac MACAddress) MarshalJSON() ([]byte, error) {
	return []byte(fmt.Sprintf("%q", mac.String())), nil
}
1140851
func VerifyMAC(mac string) bool {
	parts := strings.Split(mac, ":")
	if len(parts) != 6 {
		return false
	}
	if parts[0] != "00" || parts[1] != "50" || parts[2] != "56" {
		return false
	}
	for i, part := range parts[3:] {
		v, err := strconv.ParseUint(part, 16, 8)
		if err != nil {
			return false
		}
		if i == 0 && v > 0x3f {
			// 4th byte must be <= 0x3f
			return false
		}
	}
	return true
}
660441
func parseUint64Slice(s string) ([]uint64, error) {
	var a []uint64
	for _, str := range strings.Split(s, ",") {
		// Ignore blanks.
		if str == "" {
			continue
		}

		// Parse number.
		num, err := strconv.ParseUint(str, 10, 64)
		if err != nil {
			return nil, errors.Wrap(err, "parsing int")
		}
		a = append(a, num)
	}
	return a, nil
}
59602
func (t *Template) ParseBytes(b []byte) error {
	return t.Parse(bytes.NewReader(b))
}