You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2005/12/01 07:04:00 UTC
svn commit: r350181 [132/198] - in
/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/
depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/
depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/
depends/oss/win....
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/AllPermission.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/AllPermission.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/AllPermission.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/AllPermission.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,112 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * Subclass of Permission whose instances imply all other permissions. Granting
+ * this permission is equivalent to disabling security.
+ *
+ */
+public final class AllPermission extends Permission {
+ static final long serialVersionUID = -2916474571451318075L;
+
+ /**
+ * Constructs a new instance of this class.
+ */
+ public AllPermission() {
+ super("all_permissions");
+ }
+
+ /**
+ * Constructs a new instance of this class. The two argument version is
+ * provided for class <code>Policy</code> so that it has a consistant call
+ * pattern across all Permissions. The name and action list are both
+ * ignored.
+ *
+ * @param permissionName
+ * java.lang.String ignored.
+ * @param actions
+ * java.lang.String ignored.
+ */
+ public AllPermission(String permissionName, String actions) {
+ super("all_permissions");
+ }
+
+ /**
+ * Compares the argument to the receiver, and answers true if they represent
+ * the <em>same</em> object using a class specific comparison. All
+ * AllPermissions are equal to eachother.
+ *
+ * @param o
+ * the object to compare with this object
+ * @return <code>true</code> if the object is the same as this object
+ * <code>false</code> if it is different from this object
+ * @see #hashCode
+ */
+ public boolean equals(Object o) {
+ return o instanceof AllPermission;
+ }
+
+ /**
+ * Answers the actions associated with the receiver. Since AllPermission
+ * objects allow all actions, answer with the string "<all actions>".
+ *
+ * @return String the actions associated with the receiver.
+ */
+ public String getActions() {
+ return "<all actions>";
+ }
+
+ /**
+ * Answers an integer hash code for the receiver. Any two objects which
+ * answer <code>true</code> when passed to <code>equals</code> must
+ * answer the same value for this method.
+ *
+ * @return the receiver's hash
+ *
+ * @see #equals
+ */
+ public int hashCode() {
+ return getName().hashCode();
+ }
+
+ /**
+ * Indicates whether the argument permission is implied by the receiver.
+ * AllPermission objects imply all other permissions.
+ *
+ * @return boolean <code>true</code> if the argument permission is implied
+ * by the receiver, and <code>false</code> if it is not.
+ * @param p
+ * java.security.Permission the permission to check
+ */
+ public boolean implies(Permission p) {
+ return true;
+ }
+
+ /**
+ * Answers a new PermissionCollection for holding permissions of this class.
+ * Answer null if any permission collection can be used.
+ *
+ * @return a new PermissionCollection or null
+ *
+ * @see java.security.BasicPermissionCollection
+ */
+ public PermissionCollection newPermissionCollection() {
+ return new AllPermissionCollection();
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/AllPermissionCollection.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/AllPermissionCollection.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/AllPermissionCollection.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/AllPermissionCollection.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,47 @@
+/* Copyright 2000, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+class AllPermissionCollection extends PermissionCollection {
+ static final long serialVersionUID = -4023755556366636806L;
+
+ boolean all_allowed = false;
+
+ public void add(Permission permission) {
+ if (!(permission instanceof AllPermission)) {
+ throw new IllegalArgumentException(permission.toString());
+ }
+ if (isReadOnly()) {
+ throw new IllegalStateException();
+ }
+ all_allowed = true;
+ }
+
+ public Enumeration elements() {
+ Vector temp = new Vector();
+ if (all_allowed)
+ temp.addElement(new AllPermission());
+ return temp.elements();
+ }
+
+ public boolean implies(Permission permission) {
+ return all_allowed;
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/BasicPermission.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/BasicPermission.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/BasicPermission.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/BasicPermission.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,172 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+
+/**
+ * Superclass of permissions which have names but no action lists.
+ *
+ */
+
+public abstract class BasicPermission extends Permission implements
+ Serializable {
+ static final long serialVersionUID = 6279438298436773498L;
+
+ /**
+ * If the receiver was a correctly formatted wildcarded pattern, then this
+ * is the name with the '*' character removed. If it's not wildcarded, then
+ * it is null.
+ */
+ private transient String wildcard;
+
+ /**
+ * Creates an instance of this class with the given name and action list.
+ *
+ * @param name
+ * String the name of the new permission.
+ */
+ public BasicPermission(String name) {
+ super(name);
+ // Verified programatically that JDK only treats the permission
+ // as wildcarded if it has the shape described by this code.
+ // Names with * characters in other positions are just treated
+ // as non-wildcarded patterns, rather than exceptional conditions.
+ int length = name.length();
+ if (length > 1) {
+ if (name.charAt(length - 1) == '*'
+ && name.charAt(length - 2) == '.')
+ wildcard = name.substring(0, length - 1);
+ } else if (length == 1 && name.charAt(0) == '*') {
+ wildcard = "";
+ } else if (length == 0)
+ throw new IllegalArgumentException();
+ }
+
+ /**
+ * Creates an instance of this class with the given name and action list.
+ * The action list is ignored.
+ *
+ * @param name
+ * String the name of the new permission.
+ * @param actions
+ * String ignored.
+ */
+ public BasicPermission(String name, String actions) {
+ this(name);
+ }
+
+ /**
+ * Compares the argument to the receiver, and answers true if they represent
+ * the <em>same</em> object using a class specific comparison. In this
+ * case, the receiver and the object must have the same class and name.
+ *
+ * @param o
+ * the object to compare with this object
+ * @return <code>true</code> if the object is the same as this object
+ * <code>false</code> if it is different from this object
+ * @see #hashCode
+ */
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o != null && getClass() == o.getClass())
+ return getName().equals(((BasicPermission) o).getName());
+ return false;
+ }
+
+ /**
+ * Answers the actions associated with the receiver. BasicPermission objects
+ * have no actions, so answer the empty string.
+ *
+ * @return String the actions associated with the receiver.
+ */
+ public String getActions() {
+ return "";
+ }
+
+ /**
+ * Answers an integer hash code for the receiver. Any two objects which
+ * answer <code>true</code> when passed to <code>equals</code> must
+ * answer the same value for this method.
+ *
+ * @return int the receiver's hash
+ *
+ * @see #equals
+ */
+ public int hashCode() {
+ return getName().hashCode();
+ }
+
+ /**
+ * Indicates whether the argument permission is implied by the receiver.
+ *
+ * @return boolean <code>true</code> if the argument permission is implied
+ * by the receiver, and <code>false</code> if it is not.
+ * @param p
+ * java.security.Permission the permission to check
+ */
+ public boolean implies(Permission p) {
+ if (this == p)
+ return true;
+ if (p != null && getClass() == p.getClass()) {
+ if (wildcard != null)
+ return p.getName().startsWith(wildcard);
+ return p.getName().equals(getName());
+ }
+ return false;
+ }
+
+ /**
+ * Answers a new PermissionCollection for holding permissions of this class.
+ * Answer null if any permission collection can be used.
+ * <p>
+ * Note: For BasicPermission (and subclasses which do not override this
+ * method), the collection which is returned does <em>not</em> invoke the
+ * .implies method of the permissions which are stored in it when checking
+ * if the collection implies a permission. Instead, it assumes that if the
+ * type of the permission is correct, and the name of the permission is
+ * correct, there is a match.
+ *
+ * @return a new PermissionCollection or null
+ *
+ * @see java.security.BasicPermissionCollection
+ */
+ public PermissionCollection newPermissionCollection() {
+ return new BasicPermissionCollection();
+ }
+
+ private void readObject(ObjectInputStream stream) throws IOException,
+ ClassNotFoundException {
+ stream.defaultReadObject();
+ // Verified programatically that JDK only treats the permission
+ // as wildcarded if it has the shape described by this code.
+ // Names with * characters in other positions are just treated
+ // as non-wildcarded patterns, rather than exceptional conditions.
+ String name = getName();
+ int length = name.length();
+ if (length > 1) {
+ if (name.charAt(length - 1) == '*'
+ && name.charAt(length - 2) == '.')
+ wildcard = name.substring(0, length - 1);
+ } else if (length == 1 && name.charAt(0) == '*') {
+ wildcard = "";
+ }
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/BasicPermissionCollection.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/BasicPermissionCollection.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/BasicPermissionCollection.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/BasicPermissionCollection.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,120 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+/**
+ * A Hashtable based collection of BasicPermission objects. It make a number of
+ * assumptions about what is stored in it, allowing it to be quite performant.
+ * <p>
+ * Limitation 1: It does <em>not</em> actually check that the contained
+ * permission objects <em>grant</em> the permission being checked, only that a
+ * permission with a matching name is present. Thus, this collection can not be
+ * used where the Permission objects implement interesting semantics in their
+ * implies methods.
+ * <p>
+ * Limitation 2: It assumes (and does not check) that all permissions which are
+ * stored in the collection are instances of the same class.
+ * <p>
+ * Limitation 3: Because it uses a hashtable, it will not record the fact that
+ * multiple occurances of .equal permissions have been added.
+ *
+ */
+
+class BasicPermissionCollection extends PermissionCollection {
+ static final long serialVersionUID = 739301742472979399L;
+
+ /**
+ * A flag to indicate whether the "grant all wildcard" (i.e. "*") has been
+ * added.
+ */
+ boolean all_allowed = false;
+
+ /**
+ * A hashtable which maps from a permission name to the matching permission.
+ * Multiple occurances of the same permission are ignored.
+ */
+ Hashtable permissions = new Hashtable(8);
+
+ /**
+ * Constructs a new instance of this class.
+ *
+ */
+ public BasicPermissionCollection() {
+ super();
+ }
+
+ /**
+ * Adds the argument to the collection.
+ *
+ *
+ * @param perm
+ * java.security.Permission the permission to add to the
+ * collection
+ */
+ public void add(Permission perm) {
+ if (isReadOnly()) {
+ throw new IllegalStateException();
+ }
+ String name = perm.getName();
+ all_allowed = all_allowed || name.equals("*");
+ permissions.put(name, perm);
+ }
+
+ /**
+ * Answers an enumeration of the permissions in the receiver.
+ *
+ *
+ * @return Enumeration the permissions in the receiver.
+ */
+ public Enumeration elements() {
+ return permissions.elements();
+ }
+
+ /**
+ * Indicates whether the argument permission is implied by the permissions
+ * contained in the receiver. Note that, the permissions are not consulted
+ * during the operation of this method.
+ *
+ *
+ * @return boolean <code>true</code> if the argument permission is implied
+ * by the permissions in the receiver, and <code>false</code> if
+ * it is not.
+ * @param perm
+ * java.security.Permission the permission to check
+ */
+ public boolean implies(Permission perm) {
+ if (all_allowed)
+ return true;
+ String name = perm.getName();
+ if (permissions.get(name) != null)
+ return true;
+ int i = name.lastIndexOf('.');
+ while (i >= 0) {
+ // Fail for strings of the form "foo..bar" or "foo.".
+ if (i + 1 == name.length())
+ return false;
+ name = name.substring(0, i);
+ if (permissions.get(name + ".*") != null)
+ return true;
+ i = name.lastIndexOf('.');
+ }
+ return false;
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/CodeSource.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/CodeSource.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/CodeSource.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/CodeSource.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,312 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.URL;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+/**
+ * This class represents a "source of code" which is taken to be an URL
+ * representing the location where that code was loaded from, and a list of
+ * certificates that were used to verify that code.
+ *
+ */
+public class CodeSource extends Object implements java.io.Serializable {
+ static final long serialVersionUID = 4977541819976013951L;
+
+ /**
+ * The URL which was used to create the receiver.
+ */
+ private URL location;
+
+ /**
+ * The Certificates which were used to create the receiver.
+ */
+ private transient Certificate[] certificates;
+
+ /**
+ * A hashtable containing the values from the certificates array.
+ */
+ private transient Hashtable certificatesSet;
+
+ /**
+ * Constructs a new instance of this class with its url and certificates
+ * fields filled in from the arguments.
+ *
+ * @param url
+ * URL the URL.
+ * @param certificates
+ * Certificate[] the Certificates.
+ */
+ public CodeSource(URL url, Certificate[] certificates) {
+ location = url;
+ if (certificates != null) {
+ this.certificates = (Certificate[]) certificates.clone();
+ certificatesSet = new Hashtable(certificates.length * 3 / 2);
+ for (int i = 0; i < certificates.length; ++i)
+ if (certificates[i] != null)
+ certificatesSet.put(certificates[i], "ignored");
+ if (certificatesSet.size() == 0)
+ certificatesSet = null;
+ }
+ }
+
+ /**
+ * Compares the argument to the receiver, and answers true if they represent
+ * the <em>same</em> object using a class specific comparison. In this
+ * case, the receiver and the object must have the same URL and the same
+ * collection of certificates.
+ *
+ *
+ * @param o
+ * the object to compare with this object
+ * @return <code>true</code> if the object is the same as this object
+ * <code>false</code> if it is different from this object
+ * @see #hashCode
+ */
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null)
+ return false;
+ if (this.getClass() != o.getClass())
+ return false;
+ CodeSource other = (CodeSource) o;
+
+ // Check if URLs match.
+ URL myLocation = this.getLocation();
+ if (myLocation == null) {
+ if (other.getLocation() != null)
+ return false;
+ } else {
+ if (!myLocation.equals(other.getLocation()))
+ return false;
+ }
+
+ // URLs match, so check certificates.
+ if (certificatesSet == null) {
+ if (other.certificatesSet != null)
+ return false;
+ } else {
+ // This code relies on the assumption that, multiple copies
+ // of the same certificate do not contribute anything interesting
+ // to the differences. For example, if two code sources differ
+ // in that the first has two certificate "A"s and one certificate
+ // "B", while the other has two certificate "B"s and one certificate
+ // "A", they should still be considered the same.
+ if (other.certificatesSet == null)
+ return false;
+ if (certificatesSet.size() != other.certificatesSet.size())
+ return false;
+ Enumeration keysEnum = certificatesSet.keys();
+ while (keysEnum.hasMoreElements())
+ if (!other.certificatesSet.containsKey(keysEnum.nextElement()))
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Answers an integer hash code for the receiver. Any two objects which
+ * answer <code>true</code> when passed to <code>.equals</code> must
+ * answer the same value for this method.
+ *
+ *
+ * @return int the receiver's hash.
+ *
+ * @see #equals
+ */
+ public int hashCode() {
+ URL myLocation = this.getLocation();
+ if (myLocation == null) {
+ return 1313;
+ }
+ return myLocation.hashCode();
+ }
+
+ /**
+ * Answers the certificates held onto by the receiver.
+ *
+ *
+ * @return Certificate[] the receiver's certificates
+ */
+ public final Certificate[] getCertificates() {
+ if (certificates == null)
+ return null;
+ return (Certificate[]) certificates.clone();
+ }
+
+ /**
+ * Answers the receiver's location.
+ *
+ *
+ * @return URL the receiver's URL
+ */
+ public final URL getLocation() {
+ return location;
+ }
+
+ /**
+ * Indicates whether the argument code source is implied by the receiver.
+ *
+ *
+ * @return boolean <code>true</code> if the argument code source is
+ * implied by the receiver, and <code>false</code> if it is not.
+ * @param other
+ * CodeSource the code source to check
+ */
+ public boolean implies(CodeSource other) {
+ if (other == null)
+ return false;
+ if (this == other)
+ return true;
+
+ // Check certificates: If I have certificates,
+ // then they must all be in the other one.
+ if (certificatesSet != null) {
+ if (other.certificatesSet == null)
+ return false;
+ Enumeration keysEnum = certificatesSet.keys();
+ while (keysEnum.hasMoreElements())
+ if (!other.certificatesSet.containsKey(keysEnum.nextElement()))
+ return false;
+ }
+
+ // Check the URLs. There are some very subtle rules being encoded
+ // here.
+ URL myURL = this.getLocation();
+ if (myURL != null) {
+ URL hisURL = other.getLocation();
+ if (hisURL == null)
+ return false;
+ if (myURL.equals(hisURL))
+ return true;
+ if (!myURL.getProtocol().equals(hisURL.getProtocol()))
+ return false;
+ if (myURL.getHost() != null) {
+ if (hisURL.getHost() == null
+ || !new java.net.SocketPermission(myURL.getHost(),
+ "resolve")
+ .implies(new java.net.SocketPermission(hisURL
+ .getHost(), "resolve")))
+ return false;
+ }
+ if (myURL.getPort() != -1 && myURL.getPort() != hisURL.getPort())
+ return false;
+ String myFile = myURL.getFile();
+ String hisFile = hisURL.getFile();
+ if (myFile != null && !myFile.equals(hisFile)) {
+ if (myFile.endsWith("/-")) {
+ if (!hisFile.startsWith(myFile.substring(0,
+ myFile.length() - 1)))
+ return false;
+ } else if (myFile.endsWith("/*")) {
+ if ((!hisFile.startsWith(myFile.substring(0, myFile
+ .length() - 1)))
+ || (hisFile.indexOf('/', myFile.length()) > 0))
+ return false;
+ } else if (!myFile.endsWith("/")) {
+ if (!hisFile.equals(myFile + "/"))
+ return false;
+ } else
+ return false;
+ }
+ if (myURL.getRef() != null
+ && !myURL.getRef().equals(hisURL.getRef()))
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Answers a string containing a concise, human-readable description of the
+ * receiver.
+ *
+ *
+ * @return a printable representation for the receiver.
+ */
+ public String toString() {
+ StringBuffer result = new StringBuffer("CodeSource : "); //$NON-NLS-1$
+
+ if (certificates == null || certificates.length == 0) {
+ result.append(location + " : no certificates"); //$NON-NLS-1$
+ } else {
+ result.append(location + " : " + certificates); //$NON-NLS-1$
+ }
+ return result.toString();
+ }
+
+ private void writeObject(ObjectOutputStream stream) throws IOException {
+ stream.defaultWriteObject();
+ if (certificates == null) {
+ stream.writeInt(0);
+ } else {
+ stream.writeInt(certificates.length);
+ for (int i = 0; i < certificates.length; i++) {
+ stream.writeUTF(certificates[i].getType());
+ try {
+ byte[] encoded = certificates[i].getEncoded();
+ stream.writeInt(encoded.length);
+ stream.write(encoded);
+ } catch (CertificateEncodingException e) {
+ stream.writeInt(0);
+ }
+ }
+ }
+ }
+
+ private void readObject(ObjectInputStream stream) throws IOException,
+ ClassNotFoundException {
+ stream.defaultReadObject();
+ int count = stream.readInt();
+ if (count > 0) {
+ certificates = new Certificate[count];
+ for (int i = 0; i < count; i++) {
+ String type = stream.readUTF();
+ int length = stream.readInt();
+ if (length > 0) {
+ byte[] encoded = new byte[length];
+ stream.read(encoded);
+ try {
+ CertificateFactory factory = CertificateFactory
+ .getInstance(type);
+ certificates[i] = factory
+ .generateCertificate(new ByteArrayInputStream(
+ encoded));
+ } catch (CertificateException e) {
+ }
+ }
+ }
+ certificatesSet = new Hashtable(certificates.length * 3 / 2);
+ for (int i = 0; i < certificates.length; ++i)
+ if (certificates[i] != null)
+ certificatesSet.put(certificates[i], "ignored");
+ if (certificatesSet.size() == 0)
+ certificatesSet = null;
+ }
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DigestException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DigestException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DigestException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DigestException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,45 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * This class represents exceptions for message digest computation.
+ *
+ */
+public class DigestException extends GeneralSecurityException {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ *
+ */
+ public DigestException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public DigestException(String detailMessage) {
+ super(detailMessage);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DigestInputStream.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DigestInputStream.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DigestInputStream.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DigestInputStream.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,165 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.io.IOException;
+
+/**
+ * This class implements a stream that computes a message digest hash as the
+ * bytes are read from it.
+ *
+ */
+public class DigestInputStream extends java.io.FilterInputStream {
+
+ /**
+ * The digest to use when computing the hash.
+ */
+ protected MessageDigest digest;
+
+ /**
+ * True if the digest should be computed for the next chunck of bytes read.
+ */
+ private boolean on;
+
+ /**
+ * Constructs a new DigestInputStream on an existing stream with the given
+ * MessageDigest.
+ *
+ *
+ *
+ * @param in
+ * java.io.InputStream source of the bytes to digest.
+ * @param digest
+ * java.security.MessageDigest digest to use when computing the
+ * hash.
+ *
+ * @see #on
+ * @see MessageDigest
+ */
+ public DigestInputStream(java.io.InputStream in, MessageDigest digest) {
+ super(in);
+ setMessageDigest(digest);
+ on(true);
+ }
+
+ /**
+ * Answers the MessageDigest which the receiver uses when computing the
+ * hash.
+ *
+ *
+ * @return MessageDigest the digest the receiver uses when computing the
+ * hash.
+ *
+ */
+ public MessageDigest getMessageDigest() {
+ return digest;
+ }
+
+ /**
+ * Enables or disables the digest function (default is on).
+ *
+ *
+ * @param on
+ * boolean true if the digest should be computed, and false
+ * otherwise.
+ *
+ * @see MessageDigest
+ */
+ public void on(boolean on) {
+ this.on = on;
+ }
+
+ /**
+ * Reads the next byte and answers it as an int. Updates the digest for the
+ * byte if this fuction is enabled.
+ *
+ *
+ * @return int the byte which was read or -1 at end of stream.
+ *
+ * @exception java.io.IOException
+ * If reading the source stream causes an IOException.
+ */
+ public int read() throws IOException {
+ int result = super.read();
+ if (on && result >= 0)
+ digest.engineUpdate((byte) result);
+ return result;
+ }
+
+ /**
+ * Reads at most <code>count</code> bytes from the Stream and stores them
+ * in the byte array <code>buffer</code> starting at <code>offset</code>.
+ * Answer the number of bytes actually read or -1. Updates the digest for
+ * the bytes being read if this fuction is enabled.
+ *
+ *
+ * @param buffer
+ * byte[] the byte array in which to store the read bytes.
+ * @param offset
+ * int the offset in <code>buffer</code> to store the read
+ * bytes.
+ * @param count
+ * int the maximum number of bytes to store in
+ * <code>buffer</code>.
+ * @return int the number of bytes actually read or -1 if end of stream.
+ *
+ * @exception java.io.IOException
+ * If reading the source stream causes an IOException.
+ */
+
+ public int read(byte[] buffer, int offset, int count) throws IOException {
+ int read = super.read(buffer, offset, count);
+ if (on && read > 0)
+ digest.engineUpdate(buffer, offset, read);
+ return read;
+ }
+
+ /**
+ * Sets the MessageDigest which the receiver will use when computing the
+ * hash.
+ *
+ *
+ * @param digest
+ * MessageDigest the digest to use when computing the hash.
+ *
+ * @see MessageDigest
+ * @see #on
+ */
+ public void setMessageDigest(MessageDigest digest) {
+ this.digest = digest;
+ }
+
+ /**
+ * Answers a string containing a concise, human-readable description of the
+ * receiver.
+ *
+ *
+ * @return String a printable representation for the receiver.
+ */
+ public String toString() {
+ StringBuffer answer = new StringBuffer("DigestInputStream");
+ if (digest != null) {
+ answer.append(" : ");
+ answer.append(digest.toString());
+ }
+ if (on)
+ answer.append(" : (digest on)");
+ else
+ answer.append(" : (digest off)");
+ return answer.toString();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DigestOutputStream.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DigestOutputStream.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DigestOutputStream.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DigestOutputStream.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,165 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.io.IOException;
+
+/**
+ * This class implements a stream that computes a message digest hash as the
+ * bytes are written to it.
+ *
+ */
+
+public class DigestOutputStream extends java.io.FilterOutputStream {
+
+ /**
+ * The digest to use when computing the hash.
+ */
+ protected MessageDigest digest;
+
+ /**
+ * True if the digest should be computed for the next chunck of bytes
+ * written.
+ */
+ private boolean on;
+
+ /**
+ * Constructs a new DigestOutputStream on an existing stream and with the
+ * given MessageDigest.
+ *
+ *
+ *
+ * @param out
+ * java.io.OutputStream where the bytes will be written to.
+ * @param digest
+ * MessageDigest digest to use when computing the hash.
+ *
+ * @see #on
+ * @see MessageDigest
+ */
+ public DigestOutputStream(java.io.OutputStream out, MessageDigest digest) {
+ super(out);
+ setMessageDigest(digest);
+ on(true);
+ }
+
+ /**
+ * Answers the MessageDigest which the receiver uses when computing the
+ * hash.
+ *
+ *
+ * @return MessageDigest the digest the receiver uses when computing the
+ * hash.
+ */
+
+ public MessageDigest getMessageDigest() {
+ return digest;
+ }
+
+ /**
+ * Enables or disables the digest function (default is on).
+ *
+ *
+ * @param on
+ * boolean true if the digest should be computed, and false
+ * otherwise.
+ *
+ * @see MessageDigest
+ */
+ public void on(boolean on) {
+ this.on = on;
+ }
+
+ /**
+ * Sets the MessageDigest which the receiver will use when computing the
+ * hash.
+ *
+ *
+ * @param digest
+ * MessageDigest the digest to use when computing the hash.
+ *
+ * @see MessageDigest
+ * @see #on
+ */
+ public void setMessageDigest(MessageDigest digest) {
+ this.digest = digest;
+ }
+
+ /**
+ * Answers a string containing a concise, human-readable description of the
+ * receiver.
+ *
+ *
+ * @return String a printable representation for the receiver.
+ */
+ public String toString() {
+ StringBuffer answer = new StringBuffer("DigestOutputStream");
+ if (digest != null) {
+ answer.append(" : ");
+ answer.append(digest.toString());
+ }
+ if (on)
+ answer.append(" : (digest on)");
+ else
+ answer.append(" : (digest off)");
+ return answer.toString();
+ }
+
+ /**
+ * Writes <code>length</code> bytes from the byte array
+ * <code>buffer</code> starting at <code>offset</code> and updates the
+ * message digest hash if this function is enabled.
+ *
+ *
+ * @param buffer
+ * byte[] the buffer to be written.
+ * @param offset
+ * int offset in buffer to begin writing.
+ * @param length
+ * int number of bytes to write.
+ *
+ * @exception java.io.IOException
+ * If an error occurs attempting to write to this stream.
+ * @exception java.lang.IndexOutOfBoundsException
+ * If offset or count are outside of bounds.
+ *
+ * @see MessageDigest
+ * @see #on
+ */
+ public void write(byte[] buffer, int offset, int length) throws IOException {
+ super.write(buffer, offset, length);
+ }
+
+ /**
+ * Writes a single byte to the receiver and updates the message digest hash
+ * if this function is enabled.
+ *
+ *
+ * @param oneByte
+ * int the byte to be written.
+ *
+ * @exception java.io.IOException
+ * If an error occurs attempting to write to the underlying
+ * stream.
+ */
+ public void write(int oneByte) throws IOException {
+ super.write(oneByte);
+ if (on)
+ digest.engineUpdate((byte) oneByte);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DomainCombiner.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DomainCombiner.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DomainCombiner.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/DomainCombiner.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,40 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * A DomainCombiner is a way to update the protection domains from an
+ * AccessControlContext
+ *
+ */
+public interface DomainCombiner {
+
+ /**
+ * Updates the protection domains given as arguments.
+ *
+ *
+ * @param executionDomains
+ * java.security.ProtectionDomain[] protection domains from the
+ * current execution Thread
+ * @param parentDomains
+ * java.security.ProtectionDomain[] protection domains from the
+ * parent Thread
+ * @return ProtectionDomain[] updated protection domains
+ */
+ public ProtectionDomain[] combine(ProtectionDomain[] executionDomains,
+ ProtectionDomain[] parentDomains);
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/GeneralSecurityException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/GeneralSecurityException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/GeneralSecurityException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/GeneralSecurityException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,45 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * This class represents the general security exception. Subclasses will
+ * represents specific security problems.
+ *
+ */
+public class GeneralSecurityException extends Exception {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ *
+ */
+ public GeneralSecurityException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public GeneralSecurityException(String detailMessage) {
+ super(detailMessage);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Guard.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Guard.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Guard.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Guard.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,37 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * This interface is implemented by objects which wish to control access to
+ * other objects.
+ *
+ */
+public interface Guard {
+ /**
+ * Checks whether access should be granted to the argument. If access is
+ * granted, this method simply returns. If it is not granted, then a
+ * <code>SecurityException</code> should be thrown.
+ *
+ *
+ * @param guardedObject
+ * java.lang.Object an object to check for accessibility
+ * @exception java.lang.SecurityException
+ * If access is not granted to the object
+ */
+ void checkGuard(Object guardedObject) throws SecurityException;
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/GuardedObject.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/GuardedObject.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/GuardedObject.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/GuardedObject.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,63 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.io.Serializable;
+
+/**
+ * GuardedObject controls access to an object, by checking all requests for the
+ * object with a Guard.
+ *
+ */
+public class GuardedObject implements Serializable {
+ static final long serialVersionUID = -5240450096227834308L;
+
+ Object object;
+
+ Guard guard;
+
+ /**
+ * Constructs a GuardedObject to protect access to the specified Object
+ * using the specified Guard.
+ *
+ * @param guardedObject
+ * the Object to guard
+ * @param theGuard
+ * the Guard
+ */
+ public GuardedObject(Object guardedObject, Guard theGuard) {
+ object = guardedObject;
+ guard = theGuard;
+ }
+
+ /**
+ * Checks whether access should be granted to the object. If access is
+ * granted, this method returns the object. If it is not granted, then a
+ * <code>SecurityException</code> is thrown.
+ *
+ *
+ * @return the guarded object
+ *
+ * @exception java.lang.SecurityException
+ * If access is not granted to the object
+ */
+ public Object getObject() throws SecurityException {
+ if (guard != null)
+ guard.checkGuard(object);
+ return object;
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/InvalidAlgorithmParameterException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/InvalidAlgorithmParameterException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/InvalidAlgorithmParameterException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/InvalidAlgorithmParameterException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,45 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * This class represents invalid algorithm parameters to cryprographic services.
+ *
+ */
+public class InvalidAlgorithmParameterException extends
+ GeneralSecurityException {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ *
+ */
+ public InvalidAlgorithmParameterException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public InvalidAlgorithmParameterException(String detailMessage) {
+ super(detailMessage);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/InvalidKeyException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/InvalidKeyException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/InvalidKeyException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/InvalidKeyException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,46 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * Used when invalid cryptography keys are used.
+ *
+ * @see Throwable
+ * @see Error
+ */
+public class InvalidKeyException extends KeyException {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ *
+ */
+ public InvalidKeyException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public InvalidKeyException(String detailMessage) {
+ super(detailMessage);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/InvalidParameterException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/InvalidParameterException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/InvalidParameterException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/InvalidParameterException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,44 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * This exception is thrown when an invalid parameter is passed to a method.
+ *
+ */
+public class InvalidParameterException extends IllegalArgumentException {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ *
+ */
+ public InvalidParameterException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public InvalidParameterException(String detailMessage) {
+ super(detailMessage);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Key.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Key.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Key.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Key.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,56 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * Defines the basic properties of all key objects.
+ *
+ * @see PublicKey
+ */
+
+public interface Key extends java.io.Serializable {
+
+ // Set the version id so we are field-compatible with JDK.
+ public static final long serialVersionUID = 6603384152749567654L;
+
+ /**
+ * Answers the name of the algorithm that this key will work with. If the
+ * algorithm is unknown, it answers null.
+ *
+ *
+ * @return String the receiver's algorithm
+ */
+ public abstract String getAlgorithm();
+
+ /**
+ * Answers the encoded form of the receiver.
+ *
+ *
+ * @return byte[] the encoded form of the receiver
+ */
+ public abstract byte[] getEncoded();
+
+ /**
+ * Answers the name of the format used to encode the key, or null if it can
+ * not be encoded.
+ *
+ *
+ * @return String the receiver's encoding format
+ */
+ public abstract String getFormat();
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/KeyException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/KeyException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/KeyException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/KeyException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,48 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * This class is the superclass of all classes which represent problems with
+ * keys.
+ *
+ *
+ * @see Throwable
+ * @see Error
+ */
+public class KeyException extends GeneralSecurityException {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ *
+ */
+ public KeyException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public KeyException(String detailMessage) {
+ super(detailMessage);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/MessageDigest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/MessageDigest.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/MessageDigest.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/MessageDigest.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,439 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * Makes available message digest algorithm functionality.
+ */
+public abstract class MessageDigest extends java.security.MessageDigestSpi {
+
+ // Key prefix for algorithm name lookup
+ private static final String KEY_PREFIX = "MessageDigest.";
+
+ // Name of the digest algorithm represented by the receiver
+ private String algorithmName;
+
+ // Provider of the digest algorithm represented by the receiver.
+ private Provider provider;
+
+ // *** WARNING *** - The provider is not passed as parameter to the
+ // constructor. It means it will be uninitialized until an actual binding
+ // to a concrete class by a provider is performed, in getInstance.
+
+ // This one is tricky. Providers are supposed to subclass MessageDigestSpi,
+ // but method getInstance in MessageDigest returns a MessageDigest.
+ // Therefore, there is no way we can return the user-provider class
+ // directly (incompatible types).
+ // We need to return a MessageDigest (or subclass) instance, but
+ // somehow have a reference to the provider digest instance. This is what
+ // the Wrapper class below implements.
+ static private class Wrapper extends MessageDigest {
+ MessageDigestSpi providerDigest;
+
+ Wrapper(MessageDigestSpi providerDigest, String algorithmName) {
+ // Just because there is no empty constructor in the superclass
+ super(algorithmName);
+ this.providerDigest = providerDigest;
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ Wrapper clone = new Wrapper((MessageDigestSpi) providerDigest
+ .clone(), getAlgorithm());
+ clone.setProvider(getProvider());
+ return clone;
+ }
+
+ protected byte[] engineDigest() {
+ return providerDigest.engineDigest();
+ }
+
+ protected void engineReset() {
+ providerDigest.engineReset();
+ }
+
+ protected void engineUpdate(byte bytesToHash[], int offset, int count) {
+ providerDigest.engineUpdate(bytesToHash, offset, count);
+ }
+
+ protected void engineUpdate(byte byteToHash) {
+ providerDigest.engineUpdate(byteToHash);
+ }
+
+ protected int engineGetDigestLength() {
+ return providerDigest.engineGetDigestLength();
+ }
+ }
+
+ /**
+ * Create a new MessageDigest with its algorithm set to the argument.
+ *
+ *
+ * @param algorithmName
+ * java.lang.String the algorithm that the receiver will
+ * represent
+ */
+ protected MessageDigest(String algorithmName) {
+ setAlgorithm(algorithmName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#clone()
+ */
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ /**
+ * Computes and answers the final hash value that the receiver represents.
+ * After the digest is computed the receiver is reset.
+ *
+ * @return the hash the receiver computed
+ *
+ * @see #reset
+ */
+ public byte[] digest() {
+ byte[] answer = engineDigest();
+ reset();
+ return answer;
+ }
+
+ /**
+ * Includes the bytes of the argument in the hash value computed by the
+ * receiver, and then computes the final digest value.
+ *
+ * @param bytesToHash
+ * byte[] the source array
+ * @return the hash the receiver computed
+ *
+ * @see #update(byte)
+ * @see #update(byte[])
+ * @see #update(byte[], int, int)
+ * @see #digest()
+ * @see #digest(byte[])
+ * @see #digest(byte[], int, int)
+ */
+ public byte[] digest(byte bytesToHash[]) {
+ update(bytesToHash);
+ return digest();
+ }
+
+ /**
+ * Computes the digest and stores it into the buffer passed as parameter.
+ *
+ * @param computedDigest
+ * byte[] the array into which to store the digest
+ * @param offset
+ * the starting offset into the array
+ * @param count
+ * the number of bytes available to store the digest
+ *
+ * @exception DigestException
+ * If an error occurs
+ *
+ * @return the number of bytes copied
+ * @see #digest()
+ * @see #digest(byte[])
+ * @see #digest(byte[], int, int)
+ */
+ public int digest(byte computedDigest[], int offset, int count)
+ throws DigestException {
+ byte[] digest = digest();
+ int toCopy = count;
+ if (digest.length < toCopy)
+ toCopy = digest.length;
+ System.arraycopy(digest, 0, computedDigest, offset, toCopy);
+ return toCopy;
+ }
+
+ /**
+ * Answers the standard Java Security name for the algorithm being used by
+ * the receiver.
+ *
+ * @return String the name of the algorithm
+ */
+ public final String getAlgorithm() {
+ return algorithmName;
+ }
+
+ /**
+ * Return the engine digest length in bytes. Default is 0.
+ *
+ * @return int the engine digest length in bytes
+ *
+ */
+ public final int getDigestLength() {
+ return engineGetDigestLength();
+ }
+
+ /**
+ * Answers a new MessageDigest which is capable of running the algorithm
+ * described by the argument. The result will be an instance of a subclass
+ * of MessageDigest which implements that algorithm.
+ *
+ *
+ * @param algorithmName
+ * java.lang.String Name of the algorithm desired
+ * @return MessageDigest a concrete implementation for the algorithm
+ * desired.
+ *
+ * @exception NoSuchAlgorithmException
+ * If the algorithm cannot be found
+ */
+ public static MessageDigest getInstance(String algorithmName)
+ throws NoSuchAlgorithmException {
+
+ if (algorithmName == null)
+ throw new IllegalArgumentException();
+
+ Provider[] providers = Security.getProviders();
+ for (int i = 0; i < providers.length; i++) {
+ Provider provider = providers[i];
+ MessageDigest digest = toMessageDigestImplementation(algorithmName,
+ provider);
+ if (digest != null)
+ return digest;
+ }
+
+ // Scanned all, found nothing
+ throw new NoSuchAlgorithmException(algorithmName);
+ }
+
+ /**
+ * Answers a new MessageDigest which is capable of running the algorithm
+ * described by the argument. The result will be an instance of a subclass
+ * of MessageDigest which implements that algorithm.
+ *
+ *
+ * @param algorithmName
+ * java.lang.String Name of the algorithm desired
+ * @param providerName
+ * java.lang.String Name of the provider which has to implement
+ * the algorithm
+ * @return MessageDigest a concrete implementation for the algorithm
+ * desired.
+ *
+ * @exception NoSuchAlgorithmException
+ * If the algorithm cannot be found
+ * @exception NoSuchProviderException
+ * If the provider cannot be found
+ */
+ public static MessageDigest getInstance(String algorithmName,
+ String providerName) throws NoSuchAlgorithmException,
+ NoSuchProviderException {
+
+ if (providerName == null)
+ throw new java.lang.IllegalArgumentException();
+ if (algorithmName == null)
+ throw new java.lang.IllegalArgumentException();
+
+ Provider provider = Security.getProvider(providerName);
+ if (provider == null)
+ throw new NoSuchProviderException(providerName);
+
+ MessageDigest digest = toMessageDigestImplementation(algorithmName,
+ provider);
+ if (digest == null)
+ throw new NoSuchAlgorithmException(algorithmName);
+ return digest;
+ }
+
+ /**
+ * Answers a new MessageDigest which is capable of running the algorithm
+ * described by the argument. The result will be an instance of a subclass
+ * of MessageDigest which implements that algorithm.
+ *
+ *
+ * @param algorithm
+ * java.lang.String Name of the algorithm desired
+ * @param provider
+ * Provider Provider which has to implement the algorithm
+ * @return MessageDigest a concrete implementation for the algorithm
+ * desired.
+ *
+ * @exception NoSuchAlgorithmException
+ * If the algorithm cannot be found
+ */
+ public static MessageDigest getInstance(String algorithm, Provider provider)
+ throws NoSuchAlgorithmException {
+ if ((algorithm == null) || (provider == null)) {
+ throw new IllegalArgumentException();
+ }
+
+ return toMessageDigestImplementation(algorithm, provider);
+
+ }
+
+ /**
+ * Returns the Provider of the digest represented by the receiver.
+ *
+ * @return Provider an instance of a subclass of java.security.Provider
+ */
+ public final Provider getProvider() {
+ return provider;
+ }
+
+ /**
+ * Does a simply byte-per-byte compare of the two digests.
+ *
+ * @param digesta
+ * One of the digests to compare
+ * @param digestb
+ * The digest to compare to
+ *
+ * @return <code>true</code> if the two hashes are equal
+ * <code>false</code> if the two hashes are not equal
+ */
+ public static boolean isEqual(byte[] digesta, byte[] digestb) {
+ return java.util.Arrays.equals(digesta, digestb);
+ }
+
+ /**
+ * Puts the receiver back in an initial state, such that it is ready to
+ * compute a new hash.
+ *
+ * @see java.security.MessageDigest.Wrapper#engineReset()
+ */
+ public void reset() {
+ engineReset();
+ }
+
+ /**
+ * Set the algorithm being used by the receiver to the argument which should
+ * be a standard Java Security algorithm name.
+ *
+ * @param algorithmName
+ * String the name of the algorithm
+ */
+ void setAlgorithm(String algorithmName) {
+ this.algorithmName = algorithmName;
+ }
+
+ /**
+ * Set the provider being used by the receiver to the argument which should
+ * be an instance of a subclass of Provider
+ *
+ * @param provider
+ * the Provider for the receiver
+ */
+ void setProvider(Provider provider) {
+ this.provider = provider;
+ }
+
+ /**
+ * Answers a MessageDigest for the algorithm name supplied by the given
+ * provider.
+ *
+ *
+ * @param algorithmName
+ * java.lang.String the name of the algorithm to search for
+ * @param provider
+ * java.security.Provider the provider desired for the algorithm.
+ *
+ * @return The message digest for the algorithm name supplied by the given
+ * provider.
+ *
+ */
+ private static MessageDigest toMessageDigestImplementation(
+ String algorithmName, Provider provider) {
+ // First try to find the class corresponding to the algorithm name
+ String digestClassName;
+ try {
+ digestClassName = provider
+ .lookupProperty(KEY_PREFIX, algorithmName);
+ if (digestClassName == null)
+ return null;
+ } catch (ClassCastException e) {
+ return null;
+ }
+
+ // Now try to instantiate the digest.
+ try {
+ Class digestClass = Class.forName(digestClassName, true, provider
+ .getClass().getClassLoader());
+ MessageDigestSpi providedDigest = (MessageDigestSpi) digestClass
+ .newInstance();
+ MessageDigest digest;
+ if (providedDigest instanceof MessageDigest)
+ digest = (MessageDigest) providedDigest;
+ else
+ digest = new Wrapper(providedDigest, algorithmName);
+ digest.setProvider(provider);
+ return digest;
+ } catch (ClassNotFoundException ex) {
+ // Intentionally empty
+ } catch (IllegalAccessException e) {
+ // Intentionally empty
+ } catch (InstantiationException e) {
+ // Intentionally empty
+ } catch (ClassCastException e) {
+ // Intentionally empty
+ }
+ return null;
+ }
+
+ /**
+ * Answers a string containing a concise, human-readable description of the
+ * receiver.
+ *
+ * @return a printable representation for the receiver.
+ */
+ public String toString() {
+ return "MessageDigest : algorithm " + getAlgorithm() //$NON-NLS-1$
+ + " from provider " + getProvider().getName(); //$NON-NLS-1$
+ }
+
+ /**
+ * Includes the bytes of the argument in the hash value computed by the
+ * receiver.
+ *
+ * @param bytesToHash
+ * byte[] the source array
+ */
+ public void update(byte bytesToHash[]) {
+ engineUpdate(bytesToHash, 0, bytesToHash.length);
+ }
+
+ /**
+ * Includes a range of bytes from the first argument in the hash value
+ * computed by the receiver.
+ *
+ * @param bytesToHash
+ * byte[] the source array
+ * @param offset
+ * the starting offset into the array
+ * @param count
+ * the number of bytes to include in the hash
+ */
+ public void update(byte bytesToHash[], int offset, int count) {
+ engineUpdate(bytesToHash, offset, count);
+ }
+
+ /**
+ * Includes the argument in the hash value computed
+ * by the receiver.
+ *
+ * @param byteToHash byte
+ * the byte to feed to the hash algorithm
+ *
+ * @see #reset()
+ */
+ public void update(byte byteToHash) {
+ engineUpdate(byteToHash);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/MessageDigestSpi.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/MessageDigestSpi.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/MessageDigestSpi.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/MessageDigestSpi.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,129 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * This class is a Service Provider Interface (therefore the Spi suffix) for
+ * digest algorithms to be supplied by providers. Examples of digest algorithms
+ * are MD5 and SHA.
+ *
+ * A digest is a secure hash function for a stream of bytes, like a fingerprint
+ * for the stream of bytes.
+ *
+ */
+public abstract class MessageDigestSpi {
+ /**
+ * Constructs a new instance of this class
+ *
+ */
+ public MessageDigestSpi() {
+ super();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#clone()
+ */
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ /**
+ * Actually does the work of computing the final hash value that the
+ * receiver represents, and answers the resulting value. Note that the
+ * caller must invoke <code>reset</code> before using the receiver
+ * further.
+ *
+ *
+ * @return the hash the receiver computed
+ *
+ * @see MessageDigest#reset
+ */
+ protected abstract byte[] engineDigest();
+
+ /**
+ * Returns the digest value in the buffer provided.
+ *
+ * @param buffer
+ * where to store the resultant digest
+ * @param offset
+ * where in <code>buffer</code> to store the digest
+ * @param length
+ * how many bytes in <code>buffer</code> are available for
+ * writing the digest to
+ * @return the number of bytes in <code>buffer</code> used to actually
+ * store the digest value
+ *
+ * @throws DigestException
+ * if <code>length</code> is not big enough for the result
+ * digest
+ */
+ protected int engineDigest(byte[] buffer, int offset, int length)
+ throws DigestException {
+ byte[] digest = engineDigest();
+ int digestLength = engineGetDigestLength();
+ if (digestLength > length)
+ throw new DigestException(); // Can't fit in the buffer
+
+ System.arraycopy(digest, 0, buffer, offset, digestLength);
+ return digestLength;
+ }
+
+ /**
+ * Return the engine digest length in bytes. Default is 0.
+ * @return int the engine digest length in bytes
+ *
+ */
+ protected int engineGetDigestLength() {
+ return 0;
+ }
+
+ /**
+ * Puts the receiver back in an initial state, such that it is ready to
+ * compute a new hash.
+ *
+ * @see MessageDigest#reset()
+ */
+ protected abstract void engineReset();
+
+ /**
+ * Includes a range of bytes from the first argument in the hash value
+ * computed by the receiver.
+ *
+ *
+ * @param bytesToHash
+ * byte[] the source array
+ * @param offset
+ * the starting offset into the array
+ * @param count
+ * the number of bytes to include in the hash
+ */
+ protected abstract void engineUpdate(byte bytesToHash[], int offset,
+ int count);
+
+ /**
+ * Includes the argument in the hash value computed by the receiver.
+ *
+ *
+ * @param byteToHash
+ * byte the byte to feed to the hash algorithm
+ *
+ * @see MessageDigest#reset()
+ */
+ protected abstract void engineUpdate(byte byteToHash);
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/NoSuchAlgorithmException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/NoSuchAlgorithmException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/NoSuchAlgorithmException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/NoSuchAlgorithmException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,47 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * Instances of this class are thrown when an attempt is made to access an
+ * algorithm which is not provided by the library.
+ *
+ * @see Throwable
+ */
+public class NoSuchAlgorithmException extends GeneralSecurityException {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ *
+ */
+ public NoSuchAlgorithmException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public NoSuchAlgorithmException(String detailMessage) {
+ super(detailMessage);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/NoSuchProviderException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/NoSuchProviderException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/NoSuchProviderException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/NoSuchProviderException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,46 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * Instances of this class are thrown when an attempt is made to access a
+ * provider by name which is not currently available.
+ *
+ *
+ * @see Throwable
+ */
+public class NoSuchProviderException extends GeneralSecurityException {
+
+ /**
+ * Constructs a new instance of this class with its walkback filled in.
+ *
+ */
+ public NoSuchProviderException() {
+ super();
+ }
+
+ /**
+ * Constructs a new instance of this class with its walkback and message
+ * filled in.
+ *
+ * @param detailMessage
+ * String The detail message for the exception.
+ */
+ public NoSuchProviderException(String detailMessage) {
+ super(detailMessage);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Permission.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Permission.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Permission.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/Permission.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,148 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+import java.io.Serializable;
+
+
+/**
+ * Abstract superclass of all classes which represent permission to access
+ * system resources.
+ *
+ */
+public abstract class Permission implements Guard, Serializable {
+ static final long serialVersionUID = -5636570222231596674L;
+
+ /**
+ * The name of the permission.
+ */
+ private String name;
+
+ /**
+ * Constructs a new instance of this class with its name set to the
+ * argument.
+ *
+ *
+ * @param permissionName
+ * String the name of the permission.
+ */
+ public Permission(String permissionName) {
+ name = permissionName;
+ }
+
+ /**
+ * Compares the argument to the receiver, and answers true if they represent
+ * the <em>same</em> object using a class specific comparison. The
+ * implementation in Object answers true only if the argument is the exact
+ * same object as the receiver (==).
+ *
+ *
+ * @param o
+ * Object the object to compare with this object.
+ * @return boolean <code>true</code> if the object is the same as this
+ * object <code>false</code> if it is different from this object.
+ * @see #hashCode
+ */
+ public abstract boolean equals(Object o);
+
+ /**
+ * Answers an integer hash code for the receiver. Any two objects which
+ * answer <code>true</code> when passed to <code>.equals</code> must
+ * answer the same value for this method.
+ *
+ *
+ * @return int the receiver's hash.
+ *
+ * @see #equals
+ */
+ public abstract int hashCode();
+
+ /**
+ * Checks that the receiver is granted in the current access control context
+ * (Guard interface). Note that the argument is not currently used.
+ *
+ *
+ * @param object
+ * Object ignored.
+ *
+ * @exception java.lang.SecurityException
+ * If access is not granted
+ */
+ public void checkGuard(Object object) throws SecurityException {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(this);
+ }
+
+ /**
+ * Answers the actions associated with the receiver. Subclasses should
+ * return their actions in canonical form. If no actions are associated with
+ * the receiver, the empty string should be returned.
+ *
+ *
+ * @return String the receiver's actions.
+ */
+ public abstract String getActions();
+
+ /**
+ * Answers the name of the receiver.
+ *
+ *
+ * @return String the receiver's name.
+ */
+ public final String getName() {
+ return name;
+ }
+
+ /**
+ * Indicates whether the argument permission is implied by the receiver.
+ *
+ *
+ * @return boolean <code>true</code> if the argument permission is implied
+ * by the receiver, and <code>false</code> if it is not.
+ * @param permission
+ * Permission the permission to check.
+ */
+ public abstract boolean implies(Permission permission);
+
+ /**
+ * Answers a new PermissionCollection for holding permissions of this class.
+ * Answer null if any permission collection can be used.
+ *
+ *
+ * @return PermissionCollection or null a suitable permission collection for
+ * instances of the class of the receiver.
+ */
+ public PermissionCollection newPermissionCollection() {
+ return null;
+ }
+
+ /**
+ * Answers a string containing a concise, human-readable description of the
+ * receiver.
+ *
+ *
+ * @return String a printable representation for the receiver.
+ */
+ public String toString() {
+ StringBuffer result = new StringBuffer("Permission : "); //$NON-NLS-1$
+ result.append(getName());
+ result.append(" : with actions " + getActions()); //$NON-NLS-1$
+ return result.toString();
+ }
+
+}