directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r559789 - in /directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber: BERGeneralizedTime.java BERString.java
Date Thu, 26 Jul 2007 12:11:47 GMT
Author: elecharny
Date: Thu Jul 26 05:11:46 2007
New Revision: 559789

URL: http://svn.apache.org/viewvc?view=rev&rev=559789
Log:
Added BERStringa nd BERGeneralizedTime for Kerberos

Added:
    directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/BERGeneralizedTime.java
    directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/BERString.java

Added: directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/BERGeneralizedTime.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/BERGeneralizedTime.java?view=auto&rev=559789
==============================================================================
--- directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/BERGeneralizedTime.java
(added)
+++ directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/BERGeneralizedTime.java
Thu Jul 26 05:11:46 2007
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2000 - 2006 The Legion Of The Bouncy Castle (http://www.bouncycastle.org)
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this
+ * software and associated documentation files (the "Software"), to deal in the Software
+ * without restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to the following
+ * conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in all copies
+ * or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+ * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ * 
+ */
+
+package org.apache.directory.shared.asn1.ber;
+
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+
+/**
+ * DER Generalized time object.
+ */
+public class BERGeneralizedTime extends BERString
+{
+    private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
+
+    private static final SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyyMMddHHmmss'Z'"
);
+
+    static
+    {
+        dateFormat.setTimeZone( UTC_TIME_ZONE );
+    }
+
+
+    /**
+     * Basic DERObject constructor.
+     */
+    BERGeneralizedTime(byte[] value)
+    {
+        super( value );
+    }
+
+
+    /**
+     * Static factory method, type-conversion operator.
+     */
+    public static BERGeneralizedTime valueOf( Date date )
+    {
+        String dateString = null;
+
+        synchronized ( dateFormat )
+        {
+            dateString = dateFormat.format( date );
+        }
+
+        byte[] bytes = stringToByteArray( dateString );
+
+        return new BERGeneralizedTime( bytes );
+    }
+
+
+    /**
+     * Lazy accessor
+     * 
+     * @return Date representation of this BER Generalized Time
+     * @throws ParseException
+     */
+    public long getDate() throws ParseException
+    {
+        long date = 0;
+        int pos = 0;
+        
+
+        
+        return date;
+    }
+}

Added: directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/BERString.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/BERString.java?view=auto&rev=559789
==============================================================================
--- directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/BERString.java
(added)
+++ directory/shared/trunk/asn1/src/main/java/org/apache/directory/shared/asn1/ber/BERString.java
Thu Jul 26 05:11:46 2007
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2000 - 2006 The Legion Of The Bouncy Castle (http://www.bouncycastle.org)
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this
+ * software and associated documentation files (the "Software"), to deal in the Software
+ * without restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to the following
+ * conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in all copies
+ * or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
+ * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ * 
+ */
+
+package org.apache.directory.shared.asn1.ber;
+
+
+import java.io.UnsupportedEncodingException;
+
+
+/**
+ * Interface for DER string objects.
+ */
+public abstract class BERString
+{
+	protected byte[] data;
+	
+    /**
+     * Basic BERString constructor.
+     */
+    BERString( byte[] value )
+    {
+        data = value;
+    }
+
+
+    /**
+     * Lazy accessor.
+     * 
+     * @return underlying byte array converted to a String
+     */
+    public String getString()
+    {
+        return byteArrayToString( data );
+    }
+
+
+    /**
+     * Utility method for converting byte arrays to Strings.
+     * 
+     * @param bytes
+     * @return String
+     */
+    protected static String byteArrayToString( byte[] bytes )
+    {
+        try
+        {
+            return new String( bytes, "UTF-8" );
+        }
+        catch ( UnsupportedEncodingException uee )
+        {
+            return "";
+        }
+    }
+
+
+    /**
+     * Utility method for converting Strings to bytes.
+     * 
+     * @param string
+     * @return bytes
+     */
+    protected static byte[] stringToByteArray( String string )
+    {
+        try
+        {
+            return string.getBytes( "UTF-8" );
+        }
+        catch ( UnsupportedEncodingException uee )
+        {
+            return new byte[]
+                {};
+        }
+    }
+}



Mime
View raw message