func Inline(s string, with ...string) string { match := 0 return string(reSplat.ReplaceAllFunc([]byte(s), func(p []byte) []byte { repl := with[match] match += 1 if repl == "" { return p } else { return []byte(utils.EncodeUrlPath(repl)) } })) }
func (t *TokenConfiguration) Sign(job *cjobs.ContentRequest, keyId string, expiration int64) (string, error) { source := &TokenData{ Identifier: jobs.NewRequestIdentifier().String(), Locator: job.Locator, Type: job.Type, ExpirationDate: expiration, } buf := &bytes.Buffer{} encoder := json.NewEncoder(buf) if err := encoder.Encode(source); err != nil { return "", err } cipher, err := rsa.EncryptPKCS1v15(rand.Reader, t.publicKey, buf.Bytes()) if err != nil { return "", err } hash := crypto.SHA256.New() if _, err := hash.Write(cipher); err != nil { return "", err } hashed := hash.Sum(nil) sig, err := rsa.SignPKCS1v15(rand.Reader, t.privateKey, crypto.SHA256, hashed) if err != nil { return "", err } return fmt.Sprintf( "%s/%s/%s", utils.EncodeUrlPath(keyId), base64.URLEncoding.EncodeToString(sig), base64.URLEncoding.EncodeToString(cipher), ), nil }