27 lines
694 B
Go
27 lines
694 B
Go
package cli
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
const generatedSessionIDPrefix = "notarius:v1:"
|
|
|
|
func resolvePromptSessionID(explicitSessionID, inputModule string, rawInput []byte) (string, error) {
|
|
inputModule = strings.TrimSpace(inputModule)
|
|
if inputModule == "" {
|
|
return "", fmt.Errorf("resolve prompt session: input module key must not be empty")
|
|
}
|
|
if sessionID := strings.TrimSpace(explicitSessionID); sessionID != "" {
|
|
return sessionID, nil
|
|
}
|
|
|
|
hasher := sha256.New()
|
|
_, _ = hasher.Write([]byte(inputModule))
|
|
_, _ = hasher.Write([]byte{0})
|
|
_, _ = hasher.Write(rawInput)
|
|
return generatedSessionIDPrefix + hex.EncodeToString(hasher.Sum(nil)), nil
|
|
}
|