package dns

import (
	
	
	
)

// HashName hashes a string (label) according to RFC 5155. It returns the hashed string in uppercase.
func ( string,  uint8,  uint16,  string) string {
	if  != SHA1 {
		return ""
	}

	 := make([]byte, hex.DecodedLen(len()))
	,  := packStringHex(, , 0)
	if  != nil {
		return ""
	}
	 = [:]

	 := make([]byte, 255)
	,  := PackDomainName(strings.ToLower(), , 0, nil, false)
	if  != nil {
		return ""
	}
	 = [:]

	 := sha1.New()
	// k = 0
	.Write()
	.Write()
	 := .Sum(nil)

	// k > 0
	for  := uint16(0);  < ; ++ {
		.Reset()
		.Write()
		.Write()
		 = .Sum([:0])
	}

	return toBase32()
}

// Cover returns true if a name is covered by the NSEC3 record.
func ( *NSEC3) ( string) bool {
	 := HashName(, .Hash, .Iterations, .Salt)
	 := strings.ToUpper(.Hdr.Name)
	 := Split()
	if len() < 2 {
		return false
	}
	 := [:[1]-1]
	 := [[1]:]
	if !IsSubDomain(, strings.ToUpper()) { // name is outside owner zone
		return false
	}

	 := .NextDomain

	// if empty interval found, try cover wildcard hashes so nameHash shouldn't match with ownerHash
	if  ==  &&  !=  { // empty interval
		return true
	}
	if  >  { // end of zone
		if  >  { // covered since there is nothing after ownerHash
			return true
		}
		return  <  // if nameHash is before beginning of zone it is covered
	}
	if  <  { // nameHash is before ownerHash, not covered
		return false
	}
	return  <  // if nameHash is before nextHash is it covered (between ownerHash and nextHash)
}

// Match returns true if a name matches the NSEC3 record
func ( *NSEC3) ( string) bool {
	 := HashName(, .Hash, .Iterations, .Salt)
	 := strings.ToUpper(.Hdr.Name)
	 := Split()
	if len() < 2 {
		return false
	}
	 := [:[1]-1]
	 := [[1]:]
	if !IsSubDomain(, strings.ToUpper()) { // name is outside owner zone
		return false
	}
	if  ==  {
		return true
	}
	return false
}