/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 7142509
* @summary Cipher.doFinal(ByteBuffer,ByteBuffer) fails to
* process when in.remaining() == 0
*/
/*
* Simple test case to show that Cipher.doFinal(ByteBuffer, ByteBuffer) fails to
* process the data internally buffered inBB the cipher when input.remaining()
* == 0 and at least one buffer is a direct buffer.
*/
public class DirectBBRemaining {
boolean failedOnce = false;
byte[] keyBytes = new byte[8];
/*
* Iterate through various sizes to make sure that the code does empty
* blocks, single partial blocks, 1 full block, full + partial blocks,
* multiple full blocks, etc. 5 blocks (using DES) is probably overkill
* but will feel more confident the fix isn't breaking anything.
*/
+ outputFrequency + " tests...");
if (output) {
}
try {
output);
} catch (Exception e) {
failedOnce = true;
failedReason = e;
// If we got an exception, let's be safe for future
// testing and reset the cipher to a known good state.
}
}
if (failedOnce) {
throw failedReason;
}
}
private enum TestVariant {
};
if (output) {
}
switch (tv) {
case HEAP_HEAP:
break;
case HEAP_DIRECT:
break;
case DIRECT_HEAP:
break;
case DIRECT_DIRECT:
break;
}
// Process all data in one shot, but don't call doFinal() yet.
if (inBB.hasRemaining()) {
throw new Exception("buffer not empty");
}
// finish encryption and process all data buffered
// validate output size
throw new Exception(
"incomplete encryption output, expected "
}
// validate output data
throw new Exception("bad encryption output");
}
throw new Exception("Internal buffers still held data!");
}
}
}
}