Author: adc
Date: Wed Apr 20 11:27:23 2005
New Revision: 162032
URL: http://svn.apache.org/viewcvs?rev=162032&view=rev
Log: (empty)
Added:
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1BitStringDecoder.java
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1BitStringEncoder.java
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1OctetStringDecoder.java
Modified:
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/EncodingFactory.java
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/Length.java
Modified:
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/EncodingFactory.java
URL:
http://svn.apache.org/viewcvs/directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/EncodingFactory.java?rev=162032&r1=162031&r2=162032&view=diff
==============================================================================
---
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/EncodingFactory.java
(original)
+++
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/EncodingFactory.java
Wed Apr 20 11:27:23 2005
@@ -16,20 +16,21 @@
*/
package org.apache.snickers.encoding;
-import java.util.HashMap;
+import java.util.Hashtable;
import java.util.Map;
import org.apache.log4j.Logger;
+
/**
* @version $Revision$ $Date: $
*/
abstract public class EncodingFactory
{
- private static Logger log = Logger.getLogger( EncodingFactory.class );
- private static Map factories = new HashMap();
- private static Map encoders = new HashMap();
- private static Map decoders = new HashMap();
+ private final static Logger log = Logger.getLogger( EncodingFactory.class
);
+ private final static Map factories = new Hashtable();
+ private final static Map encoders = new Hashtable();
+ private final static Map decoders = new Hashtable();
abstract public String getEncoding();
@@ -38,14 +39,14 @@
abstract protected Decoder obtainDecoder( Class type );
- static public Encoder getEncoder( String encoding, Class type )
+ static final public Encoder getEncoder( String encoding, Class type )
{
if ( log.isDebugEnabled() ) log.debug( "Looking for encoder for " +
encoding );
Map map = (Map) encoders.get( encoding );
if ( map == null )
{
- map = new HashMap();
+ map = new Hashtable();
encoders.put( encoding, map );
}
@@ -65,14 +66,14 @@
return result;
}
- static public Decoder getDecoder( String encoding, Class type )
+ static final public Decoder getDecoder( String encoding, Class type )
{
if ( log.isDebugEnabled() ) log.debug( "Looking for decoder for " +
encoding );
Map map = (Map) decoders.get( encoding );
if ( map == null )
{
- map = new HashMap();
+ map = new Hashtable();
decoders.put( encoding, map );
}
@@ -92,7 +93,7 @@
return result;
}
- static public void register( EncodingFactory factory )
+ static final public void register( EncodingFactory factory )
{
factories.put( factory.getEncoding(), factory );
if ( encoders.containsKey( factory.getEncoding() ) ) ( (Map)
encoders.get( factory.getEncoding() ) ).clear();
Added:
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1BitStringDecoder.java
URL:
http://svn.apache.org/viewcvs/directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1BitStringDecoder.java?rev=162032&view=auto
==============================================================================
---
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1BitStringDecoder.java
(added)
+++
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1BitStringDecoder.java
Wed Apr 20 11:27:23 2005
@@ -0,0 +1,40 @@
+/**
+ *
+ * Copyright 2005 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.snickers.encoding.ber;
+
+import java.io.InputStream;
+
+import org.apache.snickers.encoding.DecoderException;
+import org.apache.snickers.runtime.ASN1BitString;
+import org.apache.snickers.runtime.ASN1Type;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ASN1BitStringDecoder implements BERDecoder
+{
+ public ASN1Type decode( BERInputStream stream ) throws DecoderException
+ {
+ return null; //To change body of implemented methods use File |
Settings | File Templates.
+ }
+
+ public ASN1Type decode( InputStream stream ) throws DecoderException
+ {
+ return null; //To change body of implemented methods use File |
Settings | File Templates.
+ }
+}
Added:
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1BitStringEncoder.java
URL:
http://svn.apache.org/viewcvs/directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1BitStringEncoder.java?rev=162032&view=auto
==============================================================================
---
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1BitStringEncoder.java
(added)
+++
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1BitStringEncoder.java
Wed Apr 20 11:27:23 2005
@@ -0,0 +1,73 @@
+/**
+ *
+ * Copyright 2005 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.snickers.encoding.ber;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.snickers.encoding.EncoderException;
+import org.apache.snickers.runtime.ASN1BitString;
+import org.apache.snickers.runtime.ASN1Type;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ASN1BitStringEncoder implements BEREncoder
+{
+ public void encode( BEROutputStream stream, ASN1Type object ) throws
EncoderException
+ {
+ ASN1BitString contextFlags = (ASN1BitString) object;
+
+ try
+ {
+ stream.encode( contextFlags );
+ }
+ catch ( IOException ioe )
+ {
+ throw new EncoderException( ioe );
+ }
+ }
+
+ public int length( int tagNumber, ASN1Type object ) throws EncoderException
+ {
+ ASN1BitString contextFlags = (ASN1BitString) object;
+
+ int length = 0;
+
+ length = Util.calculateLength( tagNumber, contextFlags.getNumBytes() +
1 );
+
+ return length;
+ }
+
+ public void encode( OutputStream stream, ASN1Type object ) throws
EncoderException
+ {
+ if ( !( object instanceof ASN1BitString ) )
+ {
+ throw new EncoderException( "Object not instance of ASN1BitString"
);
+ }
+
+ ASN1BitString bitSet = (ASN1BitString) object;
+
+ if ( !bitSet.isConsistent() )
+ {
+ throw new EncoderException( "ASN1BitString is not consistent." );
+ }
+
+ encode( new BEROutputStream( stream ), object );
+ }
+}
Added:
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1OctetStringDecoder.java
URL:
http://svn.apache.org/viewcvs/directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1OctetStringDecoder.java?rev=162032&view=auto
==============================================================================
---
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1OctetStringDecoder.java
(added)
+++
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/ASN1OctetStringDecoder.java
Wed Apr 20 11:27:23 2005
@@ -0,0 +1,39 @@
+/**
+ *
+ * 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.snickers.encoding.ber;
+
+import java.io.InputStream;
+
+import org.apache.snickers.runtime.ASN1Type;
+import org.apache.snickers.encoding.DecoderException;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ASN1OctetStringDecoder implements BERDecoder
+{
+ public ASN1Type decode( BERInputStream stream ) throws DecoderException
+ {
+ return null; //To change body of implemented methods use File |
Settings | File Templates.
+ }
+
+ public ASN1Type decode( InputStream stream ) throws DecoderException
+ {
+ return null; //To change body of implemented methods use File |
Settings | File Templates.
+ }
+}
Modified:
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/Length.java
URL:
http://svn.apache.org/viewcvs/directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/Length.java?rev=162032&r1=162031&r2=162032&view=diff
==============================================================================
---
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/Length.java
(original)
+++
directory/asn1/branches/ber-decoder/modules/runtime/src/java/org/apache/snickers/encoding/ber/Length.java
Wed Apr 20 11:27:23 2005
@@ -119,15 +119,27 @@
if ( buf.position() == 1 )
{
- // if its the long form
- if ( END_MASK == ( octet & END_MASK ) && ( octet & 0x7F ) > 0 )
+ // if its the long form, but not above 126 octets : (1)111 1111 is
not
+ // allowed : this value is reserved for future extension.
+ if ( END_MASK == ( octet & END_MASK ) )
{
// capture number of octets we need to compute length
- numOctets = octet & 0x7F;
- }
- else
- {
- fixate();
+ int typeLength = octet & 0x7F;
+
+ if ( typeLength == 0 )
+ {
+ numOctets = INDEFINITE;
+ fixate();
+ }
+ else if ( typeLength == 0x7F )
+ {
+ throw new DecoderException( "The number of octets must not
be 127 (reserved for future extension) " );
+ }
+ else
+ {
+ // capture number of octets we need to compute length
+ numOctets = octet & 0x7F;
+ }
}
}
@@ -206,8 +218,7 @@
{
length |= ( 0xFF & (int) octets.get() ) << shift;
shift += 8;
- }
- while ( octets.hasRemaining() );
+ } while ( octets.hasRemaining() );
return length;
}