2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-08-16 10:06:38 -04:00
|
|
|
package license
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2023-12-01 02:37:52 -05:00
|
|
|
// FromBytes reads the given license bytes and returns it as a string.
|
|
|
|
func FromBytes(license []byte) (string, error) {
|
|
|
|
maxSize := base64.StdEncoding.DecodedLen(len(license))
|
2022-08-16 10:06:38 -04:00
|
|
|
decodedLicense := make([]byte, maxSize)
|
2023-12-01 02:37:52 -05:00
|
|
|
n, err := base64.StdEncoding.Decode(decodedLicense, license)
|
2022-08-16 10:06:38 -04:00
|
|
|
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
|
|
|
|
}
|