Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/javax/crypto/CryptoAllPermission.java
41152 views
1
/*
2
* Copyright (c) 1999, 2019, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package javax.crypto;
27
28
import java.security.*;
29
import java.util.Enumeration;
30
import java.util.Vector;
31
32
/**
33
* The CryptoAllPermission is a permission that implies
34
* any other crypto permissions.
35
*
36
* @see java.security.Permission
37
* @see java.security.AllPermission
38
*
39
* @author Sharon Liu
40
* @since 1.4
41
*/
42
43
final class CryptoAllPermission extends CryptoPermission {
44
45
@java.io.Serial
46
private static final long serialVersionUID = -5066513634293192112L;
47
48
// This class is similar to java.security.AllPermission.
49
static final String ALG_NAME = "CryptoAllPermission";
50
static final CryptoAllPermission INSTANCE =
51
new CryptoAllPermission();
52
53
private CryptoAllPermission() {
54
super(ALG_NAME);
55
}
56
57
/**
58
* Checks if the specified permission is implied by
59
* this object.
60
*
61
* @param p the permission to check against.
62
*
63
* @return true if the specified permission is an
64
* instance of CryptoPermission.
65
*/
66
public boolean implies(Permission p) {
67
return (p instanceof CryptoPermission);
68
}
69
70
/**
71
* Checks two CryptoAllPermission objects for equality.
72
* Two CryptoAllPermission objects are always equal.
73
*
74
* @param obj the object to test for equality with this object.
75
*
76
* @return true if <i>obj</i> is a CryptoAllPermission object.
77
*/
78
public boolean equals(Object obj) {
79
return (obj == INSTANCE);
80
}
81
82
/**
83
*
84
* Returns the hash code value for this object.
85
*
86
* @return a hash code value for this object.
87
*/
88
public int hashCode() {
89
return 1;
90
}
91
92
/**
93
* Returns a new PermissionCollection object for storing
94
* CryptoAllPermission objects.
95
* <p>
96
*
97
* @return a new PermissionCollection object suitable for
98
* storing CryptoAllPermissions.
99
*/
100
public PermissionCollection newPermissionCollection() {
101
return new CryptoAllPermissionCollection();
102
}
103
}
104
105
/**
106
* A CryptoAllPermissionCollection stores a collection
107
* of CryptoAllPermission permissions.
108
*
109
* @see java.security.Permission
110
* @see java.security.Permissions
111
* @see javax.crypto.CryptoPermission
112
*
113
* @author Sharon Liu
114
*/
115
final class CryptoAllPermissionCollection extends PermissionCollection
116
implements java.io.Serializable
117
{
118
119
@java.io.Serial
120
private static final long serialVersionUID = 7450076868380144072L;
121
122
// true if a CryptoAllPermission has been added
123
private boolean all_allowed;
124
125
/**
126
* Create an empty CryptoAllPermissions object.
127
*/
128
CryptoAllPermissionCollection() {
129
all_allowed = false;
130
}
131
132
/**
133
* Adds a permission to the CryptoAllPermissions.
134
*
135
* @param permission the Permission object to add.
136
*
137
* @exception SecurityException - if this CryptoAllPermissionCollection
138
* object has been marked readonly
139
*/
140
public void add(Permission permission) {
141
if (isReadOnly())
142
throw new SecurityException("attempt to add a Permission to " +
143
"a readonly PermissionCollection");
144
145
if (permission != CryptoAllPermission.INSTANCE)
146
return;
147
148
all_allowed = true;
149
}
150
151
/**
152
* Check and see if this set of permissions implies the permissions
153
* expressed in "permission".
154
*
155
* @param permission the Permission object to compare
156
*
157
* @return true if the given permission is implied by this
158
* CryptoAllPermissionCollection.
159
*/
160
public boolean implies(Permission permission) {
161
if (!(permission instanceof CryptoPermission)) {
162
return false;
163
}
164
return all_allowed;
165
}
166
167
/**
168
* Returns an enumeration of all the CryptoAllPermission
169
* objects in the container.
170
*
171
* @return an enumeration of all the CryptoAllPermission objects.
172
*/
173
public Enumeration<Permission> elements() {
174
Vector<Permission> v = new Vector<>(1);
175
if (all_allowed) v.add(CryptoAllPermission.INSTANCE);
176
return v.elements();
177
}
178
}
179
180