Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2013-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.s3.internal.crypto;
 
 import java.io.File;
 
 import  com.amazonaws.services.s3.model.GetObjectRequest;
 import  com.amazonaws.services.s3.model.InitiateMultipartUploadRequest;
 import  com.amazonaws.services.s3.model.InitiateMultipartUploadResult;
 import  com.amazonaws.services.s3.model.ObjectMetadata;
 import  com.amazonaws.services.s3.model.PutObjectRequest;
 import  com.amazonaws.services.s3.model.PutObjectResult;
 import  com.amazonaws.services.s3.model.S3Object;
 import  com.amazonaws.services.s3.model.UploadPartRequest;
 import  com.amazonaws.services.s3.model.UploadPartResult;

A proxy cryptographic module used to dispatch method calls to the appropriate underlying cryptographic module depending on the current configuration.
 
     private final CryptoMode defaultCryptoMode;
    
Encryption only (EO) cryptographic module.
 
     private final S3CryptoModuleEO eo;
    
Authenticated encryption (AE) cryptographic module.
 
     private final S3CryptoModuleAE ae;
 
     public CryptoModuleDispatcher(S3Direct s3,
             AWSCredentialsProvider credentialsProvider,
             EncryptionMaterialsProvider encryptionMaterialsProvider,
             ClientConfiguration clientConfig,
             CryptoConfiguration cryptoConfig) {
         CryptoMode cryptoMode = cryptoConfig.getCryptoMode();
         this. = cryptoMode == null ? . : cryptoMode;
         switch() {
             case :
                 this. = new S3CryptoModuleAEStrict(s3credentialsProvider,
                         encryptionMaterialsProviderclientConfigcryptoConfig);
                 this. = null;
                 break;
             case :
                 this. = new S3CryptoModuleAE(s3credentialsProvider,
                         encryptionMaterialsProviderclientConfigcryptoConfig);
                 this. = null;
                 break;
             default:
                 this. = new S3CryptoModuleEO(s3credentialsProvider,
                         encryptionMaterialsProviderclientConfigcryptoConfig);
                 this. = new S3CryptoModuleAE(s3credentialsProvider,
                         encryptionMaterialsProviderclientConfigcryptoConfig);
                 break;
         }
     }
 
     @Override
     public PutObjectResult putObjectSecurely(PutObjectRequest putObjectRequest)
             throws AmazonClientExceptionAmazonServiceException {
         return  == .
              ? .putObjectSecurely(putObjectRequest)
              : .putObjectSecurely(putObjectRequest)
              ;
     }
 
     @Override
     public S3Object getObjectSecurely(GetObjectRequest req)
             throws AmazonClientExceptionAmazonServiceException {
         // AE module can handle S3 objects encrypted in either AE or OE format
         return .getObjectSecurely(req);
     }
 
     @Override
     public ObjectMetadata getObjectSecurely(GetObjectRequest reqFile destinationFile)
             throws AmazonClientExceptionAmazonServiceException {
         // AE module can handle S3 objects encrypted in either AE or OE format
        return .getObjectSecurely(reqdestinationFile);
    }
    @Override
            CompleteMultipartUploadRequest req)
                    throws AmazonClientExceptionAmazonServiceException {
        return  == . 
             ? .completeMultipartUploadSecurely(req)
             : .completeMultipartUploadSecurely(req)
             ;
    }
    @Override
            .abortMultipartUploadSecurely(req);
        else
            .abortMultipartUploadSecurely(req);
    }
    @Override
    public InitiateMultipartUploadResult initiateMultipartUploadSecurely(
            InitiateMultipartUploadRequest req)
                    throws AmazonClientExceptionAmazonServiceException {
        return  == . 
             ? .initiateMultipartUploadSecurely(req)
             : .initiateMultipartUploadSecurely(req)
             ;
    }

    

NOTE: Because the encryption process requires context from block N-1 in order to encrypt block N, parts uploaded with the AmazonS3EncryptionClient (as opposed to the normal AmazonS3Client) must be uploaded serially, and in order. Otherwise, the previous encryption context isn't available to use when encrypting the current part.

    @Override
    public UploadPartResult uploadPartSecurely(UploadPartRequest req)
        return  == .
             ? .uploadPartSecurely(req)
             : .uploadPartSecurely(req)
             ;
    }
    @Override
        return  == . 
             ? .copyPartSecurely(req)
             : .copyPartSecurely(req)
             ;
    }
New to GrepCode? Check out our FAQ X