loader logic revised

This commit is contained in:
IliaDenisov
2026-03-16 15:48:00 +02:00
parent cc7ecf6667
commit e6c6970947
13 changed files with 530 additions and 82 deletions
+72 -3
View File
@@ -1,6 +1,10 @@
package connector
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"galaxy/model/client"
"galaxy/model/report"
)
@@ -29,7 +33,72 @@ type UIConnector interface {
}
type VersionInfo struct {
OS string `json:"os"` // Operating System name (unix, darwin, windows, etc.)
Version string `json:"version"` // Semver format: X.Y.Z
URL string `json:"url"` // Artifact download URL for this version
OS string `json:"os"` // Operating System name (unix, darwin, windows, etc.)
Version string `json:"version"` // Semver format: X.Y.Z
URL string `json:"url"` // Artifact download URL for this version
Checksum SHA256Digest `json:"sha256"` // Base64 SHA-256 checksum for artifact binary data
}
// SHA256Digest represents a SHA-256 digest in raw binary form.
//
// Internally it stores the exact 32-byte digest.
// In JSON it is encoded as a lowercase hexadecimal string of 64 characters.
type SHA256Digest [32]byte
// NewSHA256Digest calculates SHA-256 for the provided byte slice
// and returns the digest as SHA256Digest.
//
// The function does not modify the input data.
func NewSHA256Digest(data []byte) SHA256Digest {
sum := sha256.Sum256(data)
return SHA256Digest(sum)
}
// String returns the lowercase hexadecimal representation
// of the digest.
//
// The returned string always contains exactly 64 characters.
func (d SHA256Digest) String() string {
return hex.EncodeToString(d[:])
}
// MarshalJSON encodes the digest as a JSON string containing
// the lowercase hexadecimal SHA-256 value.
//
// Example JSON value:
//
// "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
func (d SHA256Digest) MarshalJSON() ([]byte, error) {
return json.Marshal(d.String())
}
// UnmarshalJSON decodes a JSON string containing a lowercase or uppercase
// hexadecimal SHA-256 value into the digest.
//
// The input must be a JSON string with exactly 64 hexadecimal characters.
func (d *SHA256Digest) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("sha256 digest must be a JSON string: %w", err)
}
if len(s) != hex.EncodedLen(len(d)) {
return fmt.Errorf("invalid SHA-256 hex length: got %d, want %d", len(s), hex.EncodedLen(len(d)))
}
decoded, err := hex.DecodeString(s)
if err != nil {
return fmt.Errorf("invalid SHA-256 hex value: %w", err)
}
copy(d[:], decoded)
return nil
}
// Equal returns true when both digests are identical.
//
// Since SHA256Digest is based on a fixed-size array, direct value comparison
// is efficient and idiomatic for non-constant-time equality checks.
func (d SHA256Digest) Equal(other SHA256Digest) bool {
return d == other
}