Author: erodriguez
Date: Mon Oct 11 20:30:02 2004
New Revision: 54650

Added:
   incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/util/
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/util/OctetUtils.java
Modified:
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/CryptoService.java
   
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/Crc32Checksum.java
Log:
Broke out octet conversion util code into own utility class.

Modified: 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/CryptoService.java
==============================================================================
--- 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/CryptoService.java
        (original)
+++ 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/CryptoService.java
        Mon Oct 11 20:30:02 2004
@@ -74,7 +74,7 @@
        public static byte[] getEncryptedTimestamp(EncryptionKey key, Date date)
                        throws KerberosException {
                EncryptionEngine encryptionEngine = 
getInstance(key.getKeyType());
-               byte[] plaintext = ConversionUtils.long2octet(date.getTime());
+               byte[] plaintext = OctetUtils.long2octet(date.getTime());
                return encryptionEngine.encrypt(plaintext, key.getKeyValue());
        }
 

Modified: 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/Crc32Checksum.java
==============================================================================
--- 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/Crc32Checksum.java
       (original)
+++ 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/Crc32Checksum.java
       Mon Oct 11 20:30:02 2004
@@ -52,7 +52,7 @@
        public synchronized byte[] calculateChecksum(byte[] data) {
                crc32.reset();
                crc32.update(data);
-               return ConversionUtils.int2octet((int) crc32.getValue());
+               return OctetUtils.int2octet((int) crc32.getValue());
        }
 
        public byte[] calculateKeyedChecksum(byte[] data, byte[] key) {

Added: 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/util/OctetUtils.java
==============================================================================
--- (empty file)
+++ 
incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/util/OctetUtils.java
     Mon Oct 11 20:30:02 2004
@@ -0,0 +1,52 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   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 org.apache.kerberos.util;
+
+public class OctetUtils {
+
+       public static long octet2long(byte[] input) {
+               return octet2long(input, 0);
+       }
+
+       public static long octet2long(byte[] input, int offset) {
+               long result = 0;
+               for (int i = 0; i < 8; i++) {
+                       if (i + offset < input.length) {
+                               result |= ((input[i + offset]) & 0xffL) << ((7 
- i) * 8);
+                       }
+               }
+               return result;
+       }
+
+       public static byte[] long2octet(long input) {
+               byte[] output = new byte[8];
+               for (int i = 0; i < 8; i++) {
+                       output[i] =     (byte)((input >>> ((7 - i) * 8)) & 
0xffL);
+               }
+               return output;
+       }
+       
+       public static byte[] int2octet(int value) {
+               byte[] bytes = new byte[4];
+               int i, shift;
+
+               for (i = 0, shift = 24; i < 4; i++, shift -= 8)
+                       bytes[i] = (byte) (0xFF & (value >> shift));
+               return bytes;
+       }
+}
+

Reply via email to