/*
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment:
*
* "This product includes software developed by IAIK of Graz University of
* Technology."
*
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Graz University of Technology" and "IAIK of Graz University of
* Technology" must not be used to endorse or promote products derived from
* this software without prior written permission.
*
* 5. Products derived from this software may not be called
* "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior
* written permission of Graz University of Technology.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* This class contains onyl static methods. It is the place for all functions
* that are used by several classes in this package.
*
* @author Karl Scheibelhofer <Karl.Scheibelhofer@iaik.at>
* @author Martin Schlaeffer <schlaeff@sbox.tugraz.at>
*/
public class Functions {
// maps between ids and their names, forward and reverse
// ids are stored as Integers to save space
// since only the lower 32 bits are ever used anyway
// mechanisms (CKM_*)
// key types (CKK_*)
// attributes (CKA_*)
// object classes (CKO_*)
/**
* For converting numbers to their hex presentation.
*/
/**
* Converts a long value to a hexadecimal String of length 16. Includes
* leading zeros if necessary.
*
* @param value The long value to be converted.
* @return The hexadecimal string representation of the long value.
*/
long currentValue = value;
for(int j = 0; j < 16; j++) {
currentValue >>>= 4;
}
}
/**
* Converts a int value to a hexadecimal String of length 8. Includes
* leading zeros if necessary.
*
* @param value The int value to be converted.
* @return The hexadecimal string representation of the int value.
*/
int currentValue = value;
for(int i = 0; i < 8; i++) {
currentValue >>>= 4;
}
}
/**
* converts a long value to a hexadecimal String
*
* @param value the long value to be converted
* @return the hexadecimal string representation of the long value
*/
}
/**
* Converts a byte array to a hexadecimal String. Each byte is presented by
* its two digit hex-code; 0x0A -> "0a", 0x00 -> "00". No leading "0x" is
* included in the result.
*
* @param value the byte array to be converted
* @return the hexadecimal string representation of the byte array
*/
return null;
}
int single;
if (single < 0x10) {
}
}
}
/**
* converts a long value to a binary String
*
* @param value the long value to be converted
* @return the binary string representation of the long value
*/
}
/**
* converts a byte array to a binary String
*
* @param value the byte array to be converted
* @return the binary string representation of the byte array
*/
}
private static class Flags {
private final long[] flagIds;
throw new AssertionError("Array lengths do not match");
}
}
boolean first = true;
if (first == false) {
}
first = false;
}
}
}
}
}, new String[] {
"CKF_TOKEN_PRESENT",
"CKF_REMOVABLE_DEVICE",
"CKF_HW_SLOT",
});
/**
* converts the long value flags to a SlotInfoFlag string
*
* @param flags the flags to be converted
* @return the SlotInfoFlag string representation of the flags
*/
}
}, new String[] {
"CKF_RNG",
"CKF_WRITE_PROTECTED",
"CKF_LOGIN_REQUIRED",
"CKF_USER_PIN_INITIALIZED",
"CKF_RESTORE_KEY_NOT_NEEDED",
"CKF_CLOCK_ON_TOKEN",
"CKF_PROTECTED_AUTHENTICATION_PATH",
"CKF_DUAL_CRYPTO_OPERATIONS",
"CKF_TOKEN_INITIALIZED",
"CKF_SECONDARY_AUTHENTICATION",
"CKF_USER_PIN_COUNT_LOW",
"CKF_USER_PIN_FINAL_TRY",
"CKF_USER_PIN_LOCKED",
"CKF_USER_PIN_TO_BE_CHANGED",
"CKF_SO_PIN_COUNT_LOW",
"CKF_SO_PIN_FINAL_TRY",
"CKF_SO_PIN_LOCKED",
"CKF_SO_PIN_TO_BE_CHANGED",
});
/**
* converts long value flags to a TokenInfoFlag string
*
* @param flags the flags to be converted
* @return the TokenInfoFlag string representation of the flags
*/
}
}, new String[] {
"CKF_RW_SESSION",
"CKF_SERIAL_SESSION",
});
/**
* converts the long value flags to a SessionInfoFlag string
*
* @param flags the flags to be converted
* @return the SessionInfoFlag string representation of the flags
*/
}
/**
* converts the long value state to a SessionState string
*
* @param state the state to be converted
* @return the SessionState string representation of the state
*/
if (state == CKS_RO_PUBLIC_SESSION) {
name = "CKS_RO_PUBLIC_SESSION";
} else if (state == CKS_RO_USER_FUNCTIONS) {
name = "CKS_RO_USER_FUNCTIONS";
} else if (state == CKS_RW_PUBLIC_SESSION) {
name = "CKS_RW_PUBLIC_SESSION";
} else if (state == CKS_RW_USER_FUNCTIONS) {
name = "CKS_RW_USER_FUNCTIONS";
} else if (state == CKS_RW_SO_FUNCTIONS) {
name = "CKS_RW_SO_FUNCTIONS";
} else {
}
return name;
}
}, new String[] {
"CKF_HW",
"CKF_ENCRYPT",
"CKF_DECRYPT",
"CKF_DIGEST",
"CKF_SIGN",
"CKF_SIGN_RECOVER",
"CKF_VERIFY",
"CKF_VERIFY_RECOVER",
"CKF_GENERATE",
"CKF_GENERATE_KEY_PAIR",
"CKF_WRAP",
"CKF_UNWRAP",
"CKF_DERIVE",
"CKF_EC_F_P",
"CKF_EC_F_2M",
"CKF_EC_ECPARAMETERS",
"CKF_EC_NAMEDCURVE",
"CKF_EC_UNCOMPRESS",
"CKF_EC_COMPRESS",
"CKF_EXTENSION",
});
/**
* converts the long value flags to a MechanismInfoFlag string
*
* @param flags the flags to be converted
* @return the MechanismInfoFlag string representation of the flags
*/
}
}
}
return name;
}
}
}
}
}
}
}
}
}
}
}
/**
* Check the given arrays for equalitiy. This method considers both arrays as
* equal, if both are <code>null</code> or both have the same length and
* contain exactly the same byte values.
*
* @param array1 The first array.
* @param array2 The second array.
* @return True, if both arrays are <code>null</code> or both have the same
* length and contain exactly the same byte values. False, otherwise.
* @preconditions
* @postconditions
*/
}
/**
* Check the given arrays for equalitiy. This method considers both arrays as
* equal, if both are <code>null</code> or both have the same length and
* contain exactly the same char values.
*
* @param array1 The first array.
* @param array2 The second array.
* @return True, if both arrays are <code>null</code> or both have the same
* length and contain exactly the same char values. False, otherwise.
* @preconditions
* @postconditions
*/
}
/**
* Check the given dates for equalitiy. This method considers both dates as
* equal, if both are <code>null</code> or both contain exactly the same char
* values.
*
* @param date1 The first date.
* @param date2 The second date.
* @return True, if both dates are <code>null</code> or both contain the same
* char values. False, otherwise.
* @preconditions
* @postconditions
*/
boolean equal = false;
equal = true;
} else {
equal = false;
}
return equal ;
}
/**
* Calculate a hash code for the given byte array.
*
* @param array The byte array.
* @return A hash code for the given array.
* @preconditions
* @postconditions
*/
int hash = 0;
}
}
return hash ;
}
/**
* Calculate a hash code for the given char array.
*
* @param array The char array.
* @return A hash code for the given array.
* @preconditions
* @postconditions
*/
int hash = 0;
}
}
return hash ;
}
/**
* Calculate a hash code for the given date object.
*
* @param date The date object.
* @return A hash code for the given date.
* @preconditions
* @postconditions
*/
int hash = 0;
}
}
}
}
return hash ;
}
}
}
}
}
}
}
}
}
static {
}
}