8784: Fix test for latest firefox.
[arvados.git] / services / keepstore / perms.go
1 package main
2
3 import (
4         "git.curoverse.com/arvados.git/sdk/go/keepclient"
5         "time"
6 )
7
8 // SignLocator takes a blobLocator, an apiToken and an expiry time, and
9 // returns a signed locator string.
10 func SignLocator(blobLocator, apiToken string, expiry time.Time) string {
11         return keepclient.SignLocator(blobLocator, apiToken, expiry, theConfig.BlobSignatureTTL.Duration(), theConfig.blobSigningKey)
12 }
13
14 // VerifySignature returns nil if the signature on the signedLocator
15 // can be verified using the given apiToken. Otherwise it returns
16 // either ExpiredError (if the timestamp has expired, which is
17 // something the client could have figured out independently) or
18 // PermissionError.
19 func VerifySignature(signedLocator, apiToken string) error {
20         err := keepclient.VerifySignature(signedLocator, apiToken, theConfig.BlobSignatureTTL.Duration(), theConfig.blobSigningKey)
21         if err == keepclient.ErrSignatureExpired {
22                 return ExpiredError
23         } else if err != nil {
24                 return PermissionError
25         }
26         return nil
27 }