// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package main

import (
	primitivestypes "github.com/aws/aws-cryptographic-material-providers-library/releases/go/primitives/awscryptographyprimitivessmithygeneratedtypes"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/clientsupplier"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/cryptographicmaterialsmanager/requiredencryptioncontext"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/cryptographicmaterialsmanager/restrictalgorithmsuite"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/keyring/awskmsdiscoverykeyring"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/keyring/awskmsdiscoverymultikeyring"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/keyring/awskmshierarchicalkeyring"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/keyring/awskmskeyring"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/keyring/awskmsmrkdiscoverykeyring"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/keyring/awskmsmrkdiscoverymultikeyring"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/keyring/awskmsmrkkeyring"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/keyring/awskmsmrkmultikeyring"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/keyring/awskmsmultikeyring"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/keyring/awskmsrsakeyring"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/keyring/ecdh"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/keyring/multikeyring"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/keyring/rawaeskeyring"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/keyring/rawrsakeyring"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/misc"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/multithreading"
	"github.com/aws/aws-encryption-sdk/releases/go/encryption-sdk/examples/utils"
)

func main() {
	const stringToEncrypt = "Text To encrypt"
	const numOfString = 10000
	clientsupplier.ClientSupplierExample(
		stringToEncrypt,
		utils.DefaultRegionMrkKeyArn(),
		utils.DefaultKMSKeyAccountID(),
		[]string{utils.AlternateRegionMrkKeyRegion()})
	misc.CommitmentPolicyExample(
		stringToEncrypt,
		utils.DefaultKMSKeyId(),
		utils.DefaultKmsKeyRegion())
	misc.SetEncryptionAlgorithmSuiteExample(stringToEncrypt)
	var maxEncryptedDataKeys int64 = 3
	misc.LimitEncryptedDataKeyExample(
		stringToEncrypt,
		utils.DefaultKMSKeyId(),
		utils.DefaultKmsKeyRegion(),
		maxEncryptedDataKeys)
	requiredencryptioncontext.RequiredEncryptionContextExample(
		stringToEncrypt,
		utils.DefaultKMSKeyId(),
		utils.DefaultKmsKeyRegion())
	restrictalgorithmsuite.SigningOnlyExample(
		stringToEncrypt,
		utils.DefaultKMSKeyId(),
		utils.DefaultKmsKeyRegion())
	// keyrings
	ecdh.PublicKeyRawEcdhDiscoveryKeyringExample(
		stringToEncrypt,
		primitivestypes.ECDHCurveSpecEccNistP256,
		utils.EccPublicKeyFileNameRecipient(),
		utils.EccPrivateKeyFileNameRecipient())
	ecdh.EphemeralRawECDHKeyringExample(
		stringToEncrypt,
		primitivestypes.ECDHCurveSpecEccNistP256,
		utils.EccPublicKeyFileNameRecipient())
	ecdh.RawECDHKeyringExample(
		stringToEncrypt,
		primitivestypes.ECDHCurveSpecEccNistP256,
		utils.EccPublicKeyFileNameRecipient(),
		utils.EccPrivateKeyFileNameSender())
	ecdh.AwsKmsEcdhKeyringExample(
		stringToEncrypt,
		primitivestypes.ECDHCurveSpecEccNistP256,
		utils.KmsEcdhKeyIdP256RecipientKeyId(),
		utils.KmsEcdhKeyIdP256SenderKeyId(),
		utils.KmsEccPublicKeyFileNameSender(),
		utils.KmsEccPublicKeyFileNameRecipient())
	ecdh.AwsKmsEcdhDiscoveryKeyringExample(
		stringToEncrypt,
		primitivestypes.ECDHCurveSpecEccNistP256,
		utils.KmsEcdhKeyIdP256RecipientKeyId(),
		utils.KmsEcdhKeyIdP256SenderKeyId(),
		utils.KmsEccPublicKeyFileNameSender(),
		utils.KmsEccPublicKeyFileNameRecipient())
	awskmskeyring.AwsKmsKeyringExample(
		stringToEncrypt,
		utils.DefaultKMSKeyId(),
		utils.DefaultKMSKeyAccountID())
	awskmsrsakeyring.AwsKmsRsaExample(
		stringToEncrypt,
		utils.TestKmsRsaKeyID(),
		utils.KmsRSAPublicKey())
	awskmsmultikeyring.AwsKmsMultiKeyringExample(
		stringToEncrypt,
		utils.DefaultKMSKeyId(),
		utils.AlternateRegionKMSKeyId(),
		utils.AlternateRegionKMSKeyRegion())
	awskmsdiscoverykeyring.AwsKmsDiscoveryKeyringExample(
		stringToEncrypt,
		utils.DefaultKMSKeyId(),
		utils.DefaultKMSKeyAccountID())
	awskmsdiscoverymultikeyring.AwsKmsDiscoveryMultiKeyringExample(
		stringToEncrypt,
		utils.DefaultKMSKeyId(),
		utils.DefaultKMSKeyAccountID(),
		utils.Regions())
	rawrsakeyring.RawRsaExample(stringToEncrypt)
	awskmsmrkkeyring.AwsKmsMrkKeyringExample(
		stringToEncrypt,
		utils.DefaultRegionMrkKeyArn(),
		utils.AlternateRegionMrkKeyArn(),
		utils.DefaultMRKKeyRegion(),
		utils.AlternateRegionMrkKeyRegion())
	awskmsmrkmultikeyring.AwsKmsMrkMultiKeyringExample(
		stringToEncrypt,
		utils.DefaultRegionMrkKeyArn(),
		utils.AlternateRegionMrkKeyArn(),
		utils.DefaultKMSKeyId(),
		utils.AlternateRegionMrkKeyRegion())
	awskmsmrkdiscoverykeyring.AwsKmsMrkDiscoveryKeyringExample(
		stringToEncrypt,
		utils.DefaultRegionMrkKeyArn(),
		utils.DefaultMRKKeyRegion(),
		utils.AlternateRegionMrkKeyRegion(),
		utils.DefaultKMSKeyAccountID())
	awskmsmrkdiscoverymultikeyring.AwsKmsMrkDiscoveryMultiKeyringExample(
		stringToEncrypt,
		utils.DefaultRegionMrkKeyArn(),
		utils.DefaultMRKKeyRegion(),
		utils.DefaultKMSKeyAccountID(),
		utils.RegionsOfMRKKeys(),
	)
	awskmshierarchicalkeyring.AwsKmsHKeyExample(
		stringToEncrypt,
		utils.KeyStoreKMSKeyRegion(),
		utils.KeyStoreRegion(),
		utils.KeyStoreKMSKeyID(),
		utils.KeyStoreName(),
		utils.LogicalKeyStoreName(),
	)
	awskmshierarchicalkeyring.CreateAndVersionBranchKeyId(
		utils.KeyStoreKMSKeyRegion(),
		utils.KeyStoreRegion(),
		utils.KeyStoreKMSKeyID(),
		utils.KeyStoreName(),
		utils.LogicalKeyStoreName(),
	)
	awskmshierarchicalkeyring.SharedCacheExample(
		stringToEncrypt,
		utils.KeyStoreKMSKeyRegion(),
		utils.KeyStoreRegion(),
		utils.KeyStoreKMSKeyID(),
		utils.KeyStoreName(),
		utils.LogicalKeyStoreName(),
	)
	rawaeskeyring.RawAesExample(stringToEncrypt)
	multikeyring.MultiKeyringExample(
		stringToEncrypt,
		utils.DefaultKMSKeyId(),
		utils.DefaultKmsKeyRegion(),
	)
	// Example with multithreading
	multithreading.AWSKMSMultiThreadTest(
		utils.GenerateUUIDTestData(numOfString),
		utils.DefaultKMSKeyId(),
		utils.DefaultKmsKeyRegion())

	// cleanup
	utils.CleanUpFiles()
}
