package security

import "github.com/fiskerinc/cloud-services/pkg/common"

func DecryptKeys(ecu *common.UpdateManifestECU) error {
	keys := ecu.ECCKeys
	if keys == nil {
		return nil
	}
	enc := Encrypt{}
	encryptor, err := enc.GetEncryptor()
	if err != nil {
		return err
	}
	priv1, err := encryptor.DecryptChunk(keys.PrivKey1.Bytes())
	if err != nil {
		return err
	}
	keys.PrivKey1.SetBytes(priv1)

	priv2, err := encryptor.DecryptChunk(keys.PrivKey2.Bytes())
	if err != nil {
		return err
	}
	keys.PrivKey2.SetBytes(priv2)

	priv3, err := encryptor.DecryptChunk(keys.PrivKey3.Bytes())
	if err != nil {
		return err
	}
	keys.PrivKey3.SetBytes(priv3)
	return nil
}
