Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/crypto/provider/Mac/LargeByteBufferTest.java
41159 views
1
/*
2
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.nio.ByteBuffer;
25
import java.security.InvalidKeyException;
26
import java.security.NoSuchAlgorithmException;
27
import java.security.NoSuchProviderException;
28
import javax.crypto.Mac;
29
import javax.crypto.SecretKey;
30
31
/**
32
* @test
33
* @bug 8048603
34
* @summary Checks if PBE algorithms work fine with large buffer
35
* @author Alexander Fomin
36
* @build Utils
37
* @run main LargeByteBufferTest
38
*/
39
public class LargeByteBufferTest implements MacTest {
40
41
private static final int BUFFER_SIZE = 65535;
42
43
/**
44
* @param args the command line arguments
45
*/
46
public static void main(String[] args) {
47
Utils.runTests(new LargeByteBufferTest());
48
}
49
50
@Override
51
public void doTest(String alg) throws NoSuchAlgorithmException,
52
InvalidKeyException, NoSuchProviderException {
53
SecretKey key = Utils.getSecretKeySpec();
54
55
// instantiate Mac object and init it with a SecretKey
56
Mac mac = Mac.getInstance(alg, "SunJCE");
57
mac.init(key);
58
59
// prepare buffer
60
byte[] data = new byte[BUFFER_SIZE];
61
for (int i = 0; i < BUFFER_SIZE; i++) {
62
data[i] = (byte) (i % 256);
63
}
64
65
ByteBuffer buf = ByteBuffer.wrap(data);
66
int limitBefore = buf.limit();
67
68
mac.update(buf);
69
mac.doFinal();
70
71
int limitAfter = buf.limit();
72
int positonAfter = buf.position();
73
74
if (limitAfter != limitBefore) {
75
System.out.println("limit after = " + limitAfter);
76
System.out.println("limit before = " + limitBefore);
77
throw new RuntimeException("Test failed: "
78
+ "limit of buffer has been chenged.");
79
}
80
81
if (positonAfter != limitAfter) {
82
System.out.println("position after = " + positonAfter);
83
System.out.println("limit after = " + limitAfter);
84
throw new RuntimeException("Test failed: "
85
+ "position of buffer isn't equal to its limit");
86
}
87
}
88
89
}
90
91