initial commit

This commit is contained in:
ston1th 2023-03-14 01:43:04 +01:00
commit 60fb40d61a
34 changed files with 2571 additions and 0 deletions

56
pkg/core/encoding.go Normal file
View file

@ -0,0 +1,56 @@
// Copyright (C) 2023 Marius Schellenberger
package core
import (
"encoding/base32"
"encoding/base64"
"encoding/hex"
)
var b32raw = base32.StdEncoding.WithPadding(base32.NoPadding)
type Encoding int
func (e Encoding) String() string {
switch e {
case Base32:
return "base32"
case Base64:
return "base64"
case Base64URL:
return "base64url"
}
return "hex"
}
func (e Encoding) EncodeToString(src []byte) string {
switch e {
case Base32:
return b32raw.EncodeToString(src)
case Base64:
return base64.RawStdEncoding.EncodeToString(src)
case Base64URL:
return base64.RawURLEncoding.EncodeToString(src)
}
return hex.EncodeToString(src)
}
func EncodingFromString(e string) Encoding {
switch e {
case "base32":
return Base32
case "base64":
return Base64
case "base64url":
return Base64URL
}
return Hex
}
const (
Hex Encoding = iota
Base32
Base64
Base64URL
)

26
pkg/core/key.go Normal file
View file

@ -0,0 +1,26 @@
// Copyright (C) 2023 Marius Schellenberger
package core
import "regexp"
const (
re = "a-zA-Z0-9_-"
id = "[a-f0-9]{32}"
nameReReverse = "[^" + re + "]+"
IDRoute = "/{id:" + id + "}"
AIDRoute = "/{aid:" + id + "}"
)
var NameRe = regexp.MustCompile(nameReReverse)
type Key struct {
ID string
Name string
Created int64
Size int
Encoding Encoding
Key string
}
type Keys []Key