mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-14 18:34:31 -05:00
0d12e37c96
* Include EXC0014 and fix issues. * Include EXC0012 and fix issues. Signed-off-by: Fabian Kammel <fk@edgeless.systems> Co-authored-by: Otto Bittner <cobittner@posteo.net>
36 lines
909 B
Go
36 lines
909 B
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package license
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"fmt"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/file"
|
|
)
|
|
|
|
// FromFile reads the license from fileHandler at path and returns it as a string.
|
|
func FromFile(fileHandler file.Handler, path string) (string, error) {
|
|
readBytes, err := fileHandler.Read(path)
|
|
if err != nil {
|
|
return "", fmt.Errorf("unable to read from '%s': %w", path, err)
|
|
}
|
|
|
|
maxSize := base64.StdEncoding.DecodedLen(len(readBytes))
|
|
decodedLicense := make([]byte, maxSize)
|
|
n, err := base64.StdEncoding.Decode(decodedLicense, readBytes)
|
|
if err != nil {
|
|
return "", fmt.Errorf("unable to base64 decode license file: %w", err)
|
|
}
|
|
if n != 36 { // length of UUID
|
|
return "", fmt.Errorf("license file corrupt: wrong length")
|
|
}
|
|
decodedLicense = decodedLicense[:n]
|
|
|
|
return string(decodedLicense), nil
|
|
}
|