-
Notifications
You must be signed in to change notification settings - Fork 5
/
utils.go
55 lines (46 loc) · 1.42 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package stoutils
import (
"io"
"path"
"strings"
"github.com/function61/gokit/cryptorandombytes"
"github.com/function61/gokit/hashverifyreader"
"github.com/function61/varasto/pkg/stotypes"
"github.com/minio/sha256-simd"
)
// this should not be called from anywhere other than DiskAccessManager and varastoclient
func BlobHashVerifier(reader io.Reader, br stotypes.BlobRef) io.Reader {
return hashverifyreader.New(reader, sha256.New(), br.AsSha256Sum())
}
// there's gonna be lots of these
var NewCollectionId = longId
var NewDirectoryId = longId
// there's going to be comparatively few of these
// (changeset IDs are unique within a collection)
var NewCollectionChangesetId = shortId
var NewVolumeMountId = shortId
var NewVolumeUuid = longId
var NewNodeId = shortId
var NewClientId = shortId
var NewIntegrityVerificationJobId = shortId
var NewReplicationPolicyId = shortId
var NewEncryptionKeyId = longId
var NewKeyEncryptionKeyId = shortId
var NewApiKeySecret = cryptoLongId
func shortId() string {
return cryptorandombytes.Base64UrlWithoutLeadingDash(3)
}
func longId() string {
return cryptorandombytes.Base64UrlWithoutLeadingDash(8)
}
func cryptoLongId() string {
return cryptorandombytes.Base64UrlWithoutLeadingDash(32)
}
func IsMaybeCompressible(filename string) bool {
switch strings.ToLower(path.Ext(filename)) {
case ".jpg", ".jpeg", ".gif", ".png", ".mp4", ".mkv", ".avi", ".mp3":
return false
default:
return true
}
}