fix golint issues in rest (#529)
This commit is contained in:
@@ -25,13 +25,19 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrInvalidContentType is an error that indicates invalid content type.
|
||||
ErrInvalidContentType = errors.New("invalid content type")
|
||||
ErrInvalidHeader = errors.New("invalid X-Content-Security header")
|
||||
ErrInvalidKey = errors.New("invalid key")
|
||||
ErrInvalidPublicKey = errors.New("invalid public key")
|
||||
ErrInvalidSecret = errors.New("invalid secret")
|
||||
// ErrInvalidHeader is an error that indicates invalid X-Content-Security header.
|
||||
ErrInvalidHeader = errors.New("invalid X-Content-Security header")
|
||||
// ErrInvalidKey is an error that indicates invalid key.
|
||||
ErrInvalidKey = errors.New("invalid key")
|
||||
// ErrInvalidPublicKey is an error that indicates invalid public key.
|
||||
ErrInvalidPublicKey = errors.New("invalid public key")
|
||||
// ErrInvalidSecret is an error that indicates invalid secret.
|
||||
ErrInvalidSecret = errors.New("invalid secret")
|
||||
)
|
||||
|
||||
// A ContentSecurityHeader is a content security header.
|
||||
type ContentSecurityHeader struct {
|
||||
Key []byte
|
||||
Timestamp string
|
||||
@@ -39,10 +45,12 @@ type ContentSecurityHeader struct {
|
||||
Signature string
|
||||
}
|
||||
|
||||
// Encrypted checks if it's a crypted request.
|
||||
func (h *ContentSecurityHeader) Encrypted() bool {
|
||||
return h.ContentType == httpx.CryptionType
|
||||
}
|
||||
|
||||
// ParseContentSecurity parses content security settings in give r.
|
||||
func ParseContentSecurity(decrypters map[string]codec.RsaDecrypter, r *http.Request) (
|
||||
*ContentSecurityHeader, error) {
|
||||
contentSecurity := r.Header.Get(httpx.ContentSecurity)
|
||||
@@ -88,6 +96,7 @@ func ParseContentSecurity(decrypters map[string]codec.RsaDecrypter, r *http.Requ
|
||||
}, nil
|
||||
}
|
||||
|
||||
// VerifySignature verifies the signature in given r.
|
||||
func VerifySignature(r *http.Request, securityHeader *ContentSecurityHeader, tolerance time.Duration) int {
|
||||
seconds, err := strconv.ParseInt(securityHeader.Timestamp, 10, 64)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,25 +2,30 @@ package security
|
||||
|
||||
import "net/http"
|
||||
|
||||
// A WithCodeResponseWriter is a helper to delay sealing a http.ResponseWriter on writing code.
|
||||
type WithCodeResponseWriter struct {
|
||||
Writer http.ResponseWriter
|
||||
Code int
|
||||
}
|
||||
|
||||
// Flush flushes the response writer.
|
||||
func (w *WithCodeResponseWriter) Flush() {
|
||||
if flusher, ok := w.Writer.(http.Flusher); ok {
|
||||
flusher.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
// Header returns the http header.
|
||||
func (w *WithCodeResponseWriter) Header() http.Header {
|
||||
return w.Writer.Header()
|
||||
}
|
||||
|
||||
// Write writes bytes into w.
|
||||
func (w *WithCodeResponseWriter) Write(bytes []byte) (int, error) {
|
||||
return w.Writer.Write(bytes)
|
||||
}
|
||||
|
||||
// WriteHeader writes code into w, and not sealing the writer.
|
||||
func (w *WithCodeResponseWriter) WriteHeader(code int) {
|
||||
w.Writer.WriteHeader(code)
|
||||
w.Code = code
|
||||
|
||||
Reference in New Issue
Block a user