• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ////////////////////////////////////////////////////////////////////////////////
16 
17 package com.google.crypto.tink.subtle;
18 
19 import java.nio.ByteBuffer;
20 import java.security.GeneralSecurityException;
21 
22 /**
23  * StreamSegmentDecrypter is a helper class that decrypts individual segments of a stream.
24  *
25  * <p>Instances of this interfaces are passed to {@link StreamingAeadDecryptingChannel}. Each
26  * instance must be initialized with the header of the ciphertext.
27  *
28  * @since 1.1.0
29  */
30 public interface StreamSegmentDecrypter {
init(ByteBuffer header, byte[] aad)31   void init(ByteBuffer header, byte[] aad) throws GeneralSecurityException;
32 
33   /**
34    * Decrypts a ciphetext segment.
35    *
36    * @param segmentNr the number of the segment
37    * @param isLastSegment true if this segment is the last segment of the ciphertext stream. The
38    *     last segment is encrypted (or authenticated) differently to detect truncated ciphertext.
39    * @param plaintext the decrypted plaintext.
40    * @throws GeneralSecurityException if ciphertext was not a valid ciphertext for the given
41    *     segment.
42    */
decryptSegment( ByteBuffer ciphertext, int segmentNr, boolean isLastSegment, ByteBuffer plaintext)43   void decryptSegment(
44       ByteBuffer ciphertext, int segmentNr, boolean isLastSegment, ByteBuffer plaintext)
45       throws GeneralSecurityException;
46 }
47