package basicauth

import (
	
	

	
)

const hashSize = 64

var _ http.Handler = (*StaticHandler)(nil)

// StaticHandler is a handler that authenticates requests using static
// credentials.
type StaticHandler struct {
	// Handler is the handler protected by HTTP basic authentication.
	Handler http.Handler
	// UserHash is username hash to compare against.
	UserHash []byte
	// PassHash is password hash to compare against.
	PassHash []byte
}

// Static returns a handler that serves requests from underlying handler after
// successful HTTP basic authentication with static credentials.
func ( http.Handler, ,  string) *StaticHandler {
	 := &StaticHandler{
		Handler:  ,
		UserHash: make([]byte, hashSize),
		PassHash: make([]byte, hashSize),
	}
	sha3.ShakeSum256(.UserHash, []byte())
	sha3.ShakeSum256(.PassHash, []byte())
	return 
}

// ServeHTTP implements the http.Handler interface.
func ( *StaticHandler) ( http.ResponseWriter,  *http.Request) {
	, ,  := .BasicAuth()

	// Use constant time comparison to guard against brute-force timing
	// attacks. Also short-circuit on ok in case there is no auth header.
	//
	var  int
	if  {
		var ,  [hashSize]byte

		sha3.ShakeSum256([:], []byte())
		sha3.ShakeSum256([:], []byte())

		 += subtle.ConstantTimeCompare(.UserHash, [:])
		 += subtle.ConstantTimeCompare(.PassHash, [:])
	}
	if ! ||  != 2 {
		.Header().Add("WWW-Authenticate", "Basic")
		.WriteHeader(http.StatusUnauthorized)
		return
	}

	.Handler.ServeHTTP(, )
}