MCPcopy Create free account
hub / github.com/encodeous/nylon / BundleConfig

Function BundleConfig

state/distribution.go:68–93  ·  view source on GitHub ↗

BundleConfig first signs the config with the root private key, ensuring the authenticity, then encrypts the message using the bytes of the root public key as the shared key, offering some level of privacy. (assuming the root public key is not shared widely)

(config string, rootKey NyPrivateKey)

Source from the content-addressed store, hash-verified

66
67// BundleConfig first signs the config with the root private key, ensuring the authenticity, then encrypts the message using the bytes of the root public key as the shared key, offering some level of privacy. (assuming the root public key is not shared widely)
68func BundleConfig(config string, rootKey NyPrivateKey) (string, error) {
69 cfg := CentralCfg{}
70 err := yaml.Unmarshal([]byte(config), &cfg)
71 if err != nil {
72 return "", err
73 }
74 err = CentralConfigValidator(&cfg)
75 if err != nil {
76 return "", err
77 }
78 cfg.Timestamp = time.Now().UnixNano()
79
80 plainText, err := yaml.Marshal(cfg)
81
82 bundle, err := SignBundle(plainText, rootKey)
83 if err != nil {
84 return "", err
85 }
86 pub := rootKey.Pubkey()
87 bundle, err = SealBundle(bundle, pub[:])
88 if err != nil {
89 return "", err
90 }
91
92 return base64.StdEncoding.EncodeToString(bundle), nil
93}
94
95func UnbundleConfig(bundleStr string, pubKey NyPublicKey) (*CentralCfg, error) {
96 bundle, err := base64.StdEncoding.DecodeString(bundleStr)

Callers 5

bundle.goFile · 0.92
TestDistributionFunction · 0.92
writeBundleFunction · 0.92
TestBundleUnbundleFunction · 0.85
TestBundleTamperFunction · 0.85

Calls 4

CentralConfigValidatorFunction · 0.85
SignBundleFunction · 0.85
SealBundleFunction · 0.85
PubkeyMethod · 0.80

Tested by 4

TestDistributionFunction · 0.74
writeBundleFunction · 0.74
TestBundleUnbundleFunction · 0.68
TestBundleTamperFunction · 0.68