Path: blob/main/components/public-api-server/pkg/auth/signature.go
2500 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package auth56import (7"crypto/hmac"8"crypto/sha256"9"fmt"10)1112type Signer interface {13Sign(message []byte) ([]byte, error)14}1516func NewHS256Signer(key []byte) *HS256Signer {17return &HS256Signer{18key: key,19}20}2122type HS256Signer struct {23key []byte24}2526// Signs message with HS256 (HMAC with SHA-256)27func (s *HS256Signer) Sign(message []byte) ([]byte, error) {28h := hmac.New(sha256.New, s.key)29_, err := h.Write(message)30if err != nil {31return nil, fmt.Errorf("failed to sign secret: %w", err)32}33return h.Sum(nil), nil34}353637