mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
4d6a7fa759
* license: refactor license check to be agnostic of input * license: remove unused code * cli: only check license file in enterprise version Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> * bazel: fix enterprise CLI build * bazel: add keep directive * Update internal/constellation/apply.go Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com> * license: check for return value --------- Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com> Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com>
28 lines
682 B
Go
28 lines
682 B
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package license
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"fmt"
|
|
)
|
|
|
|
// FromBytes reads the given license bytes and returns it as a string.
|
|
func FromBytes(license []byte) (string, error) {
|
|
maxSize := base64.StdEncoding.DecodedLen(len(license))
|
|
decodedLicense := make([]byte, maxSize)
|
|
n, err := base64.StdEncoding.Decode(decodedLicense, license)
|
|
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
|
|
}
|