[ARVADOS] created: 2.1.0-1358-g01e2aa185

Git user git at public.arvados.org
Mon Sep 20 14:10:43 UTC 2021


        at  01e2aa185d373357bad711d916ff10103c48a89a (commit)


commit 01e2aa185d373357bad711d916ff10103c48a89a
Author: Tom Clegg <tom at curii.com>
Date:   Mon Sep 20 10:10:16 2021 -0400

    18051: Reduce string operations/allocs in blob signing.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curii.com>

diff --git a/sdk/go/arvados/blob_signature.go b/sdk/go/arvados/blob_signature.go
index 2202016bc..47b31a18e 100644
--- a/sdk/go/arvados/blob_signature.go
+++ b/sdk/go/arvados/blob_signature.go
@@ -9,13 +9,13 @@
 package arvados
 
 import (
+	"bytes"
 	"crypto/hmac"
 	"crypto/sha1"
 	"errors"
 	"fmt"
 	"regexp"
 	"strconv"
-	"strings"
 	"time"
 )
 
@@ -33,9 +33,9 @@ var (
 
 // makePermSignature generates a SHA-1 HMAC digest for the given blob,
 // token, expiry, and site secret.
-func makePermSignature(blobHash, apiToken, expiry, blobSignatureTTL string, permissionSecret []byte) string {
+func makePermSignature(blobHash []byte, apiToken, expiry, blobSignatureTTL string, permissionSecret []byte) string {
 	hmac := hmac.New(sha1.New, permissionSecret)
-	hmac.Write([]byte(blobHash))
+	hmac.Write(blobHash)
 	hmac.Write([]byte("@"))
 	hmac.Write([]byte(apiToken))
 	hmac.Write([]byte("@"))
@@ -73,7 +73,10 @@ func SignLocator(blobLocator, apiToken string, expiry time.Time, blobSignatureTT
 		return blobLocator
 	}
 	// Strip off all hints: only the hash is used to sign.
-	blobHash := strings.Split(blobLocator, "+")[0]
+	blobHash := []byte(blobLocator)
+	if hints := bytes.IndexRune(blobHash, '+'); hints > 0 {
+		blobHash = blobHash[:hints]
+	}
 	timestampHex := fmt.Sprintf("%08x", expiry.Unix())
 	blobSignatureTTLHex := strconv.FormatInt(int64(blobSignatureTTL.Seconds()), 16)
 	return blobLocator +
@@ -100,7 +103,7 @@ func VerifySignature(signedLocator, apiToken string, blobSignatureTTL time.Durat
 	if matches == nil {
 		return ErrSignatureMissing
 	}
-	blobHash := matches[1]
+	blobHash := []byte(matches[1])
 	signatureHex := matches[6]
 	expiryHex := matches[7]
 	if expiryTime, err := parseHexTimestamp(expiryHex); err != nil {

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list