/** Returns the plaintext length from the request and metadata; or -1 if unknown. */ protected final long plaintextLength(PutObjectRequest request, ObjectMetadata metadata) { if (request.getFile() != null) { return request.getFile().length(); } else if (request.getInputStream() != null && metadata.getRawMetadata().get(Headers.CONTENT_LENGTH) != null) { return metadata.getContentLength(); } return -1; }
/** * Returns the content length of the unencrypted data in a PutObjectRequest, or -1 if the original * content-length isn't known. * * @param request The request to examine. * @param metadata The metadata for the request. * @return The content length of the unencrypted data in the request, or -1 if it isn't known. * @deprecated no longer used and will be removed in the future */ @Deprecated private static long getUnencryptedContentLength( PutObjectRequest request, ObjectMetadata metadata) { if (request.getFile() != null) { return request.getFile().length(); } else if (request.getInputStream() != null && metadata.getRawMetadataValue(Headers.CONTENT_LENGTH) != null) { return metadata.getContentLength(); } return -1; }
/** * Update the request's ObjectMetadata with the necessary information for decrypting the object * * @param request Non-null PUT request encrypted using the given instruction * @param instruction Non-null instruction used to encrypt the data in this PUT request. * @deprecated no longer used and will be removed in the future */ @Deprecated public static void updateMetadataWithEncryptionInstruction( PutObjectRequest request, EncryptionInstruction instruction) { byte[] keyBytesToStoreInMetadata = instruction.getEncryptedSymmetricKey(); Cipher symmetricCipher = instruction.getSymmetricCipher(); Map<String, String> materialsDescription = instruction.getMaterialsDescription(); ObjectMetadata metadata = request.getMetadata(); if (metadata == null) metadata = new ObjectMetadata(); if (request.getFile() != null) { Mimetypes mimetypes = Mimetypes.getInstance(); metadata.setContentType(mimetypes.getMimetype(request.getFile())); } updateMetadata(metadata, keyBytesToStoreInMetadata, symmetricCipher, materialsDescription); request.setMetadata(metadata); }
private CipherLiteInputStream newS3CipherLiteInputStream( PutObjectRequest req, ContentCryptoMaterial cekMaterial, long plaintextLength) { try { InputStream is = req.getInputStream(); if (req.getFile() != null) is = new RepeatableFileInputStream(req.getFile()); if (plaintextLength > -1) { // S3 allows a single PUT to be no more than 5GB, which // therefore won't exceed the maximum length that can be // encrypted either using any cipher such as CBC or GCM. // This ensures the plain-text read from the underlying data // stream has the same length as the expected total. is = new LengthCheckInputStream(is, plaintextLength, EXCLUDE_SKIPPED_BYTES); } return new CipherLiteInputStream(is, cekMaterial.getCipherLite(), DEFAULT_BUFFER_SIZE); } catch (Exception e) { throw new AmazonClientException("Unable to create cipher input stream: " + e.getMessage(), e); } }
/** * @param plaintextLength the expected total number of bytes of the plaintext; or -1 if not * available. * @deprecated no longer used and will be removed in the future */ @Deprecated private static InputStream getEncryptedInputStream( PutObjectRequest request, CipherFactory cipherFactory, long plaintextLength) { try { InputStream is = request.getInputStream(); if (request.getFile() != null) { // Historically file takes precedence over the original input // stream is = new RepeatableFileInputStream(request.getFile()); } if (plaintextLength > -1) { // This ensures the plain-text read from the underlying data // stream has the same length as the expected total is = new LengthCheckInputStream(is, plaintextLength, EXCLUDE_SKIPPED_BYTES); } return new RepeatableCipherInputStream(is, cipherFactory); } catch (Exception e) { throw new AmazonClientException("Unable to create cipher input stream: " + e.getMessage(), e); } }
/** Convenience method for getting the file specified in a request. */ public static File getRequestFile(final PutObjectRequest putObjectRequest) { if (putObjectRequest.getFile() != null) return putObjectRequest.getFile(); return null; }