func findEncryptingKey(ctx context.Context, client *registry.Client, orgID *identity.ID,
	encryptingKeyID *identity.ID) (*primitive.PublicKey, error) {

	claimTrees, err := client.ClaimTree.List(ctx, orgID, nil)
	if err != nil {
		return nil, err
	}

	if len(claimTrees) != 1 {
		return nil, &apitypes.Error{
			Type: apitypes.NotFoundError,
			Err: []string{
				fmt.Sprintf("Claim tree not found for org: %s", orgID),
			},
		}
	}

	var encryptingKey *primitive.PublicKey
	for _, segment := range claimTrees[0].PublicKeys {
		if *segment.Key.ID == *encryptingKeyID {
			encryptingKey = segment.Key.Body.(*primitive.PublicKey)
			break
		}
	}
	if encryptingKey == nil {
		return nil, &apitypes.Error{
			Type: apitypes.NotFoundError,
			Err: []string{
				fmt.Sprintf("Encrypting key not found: %s", encryptingKeyID),
			},
		}
	}

	return encryptingKey, nil
}
// findEncryptingKey queries the registry for public keys in the given org, to
// find the matching one
findEncryptingKey queries the registry for public keys in the given org, to
find the matching one
// findEncryptingKey queries the registry for public keys in the given org to // find the matching one
func findEncryptingKey(ctx context.Context, client *registry.Client, orgID *identity.ID,
	encryptingKeyID *identity.ID) (*primitive.PublicKey, error) {
	claimTrees, err := client.ClaimTree.List(ctx, orgID, nil)
	if err != nil {
		return nil, err
	}
	if len(claimTrees) != 1 {
		return nil, &apitypes.Error{
			Type: apitypes.NotFoundError,
			Err: []string{
				fmt.Sprintf("Claim tree not found for org: %s", orgID),
			},
		}
	}
	var encryptingKey *primitive.PublicKey
	for _, segment := range claimTrees[0].PublicKeys {
		if *segment.Key.ID == *encryptingKeyID {
			encryptingKey = segment.Key.Body.(*primitive.PublicKey)
			break
		}
	}
	if encryptingKey == nil {
		return nil, &apitypes.Error{
			Type: apitypes.NotFoundError,
			Err: []string{
				fmt.Sprintf("Encrypting key not found: %s", encryptingKeyID),
			},
		}
	}
	return encryptingKey, nil
}
func findEncryptingKey ( ctx context . Context , client * registry . Client , orgID * identity . ID , encryptingKeyID * identity . ID ) ( * primitive . PublicKey , error ) { claimTrees , err := client . ClaimTree . List ( ctx , orgID , nil ) if err != nil { return nil , err } if len ( claimTrees ) != 1 { return nil , & apitypes . Error { Type : apitypes . NotFoundError , Err : [ ] string { fmt . Sprintf ( " " , orgID ) , } , } } var encryptingKey * primitive . PublicKey for _ , segment := range claimTrees [ 0 ] . PublicKeys { if * segment . Key . ID == * encryptingKeyID { encryptingKey = segment . Key . Body . ( * primitive . PublicKey ) break } } if encryptingKey == nil { return nil , & apitypes . Error { Type : apitypes . NotFoundError , Err : [ ] string { fmt . Sprintf ( " " , encryptingKeyID ) , } , } } return encryptingKey , nil }
findEncryptingKey queries the registry for public keys in the given org, to
find the matching one
findEncryptingKey queries the registry for public keys in the given org to find the matching one