Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Amazon Modifications: Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved. Copyright (c) 1998-2010 AOL Inc. 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. /
 
 // http://oauth.googlecode.com/svn/code/branches/jmeter/jmeter/src/main/java/org/apache/jmeter/protocol/oauth/sampler/PrivateKeyReader.java
 
 // http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
 // http://en.wikipedia.org/wiki/Distinguished_Encoding_Rules#DER_encoding
 package com.amazonaws.auth;
 
An ASN.1 TLV. The object is not parsed. It can only handle integers and strings.

Author(s):
zhang
 
 class Asn1Object {
     protected final int type;
     protected final int length;
     protected final byte[] value;
     protected final int tag;
    
    
Construct a ASN.1 TLV. The TLV could be either a constructed or primitive entity.

The first byte in DER encoding is made of following fields,

-------------------------------------------------
|Bit 8|Bit 7|Bit 6|Bit 5|Bit 4|Bit 3|Bit 2|Bit 1|
-------------------------------------------------
|  Class    | CF  |     +      Type             |
-------------------------------------------------
 
  • Class: Universal, Application, Context or Private
  • CF: Constructed flag. If 1, the field is constructed.
  • Type: This is actually called tag in ASN.1. It indicates data type (Integer, String) or a construct (sequence, choice, set).

Parameters:
tag Tag or Identifier
length Length of the field
value Encoded octet string for the field.
 
     public Asn1Object(int tagint lengthbyte[] value) {
         this. = tag;
         this. = tag & 0x1F;
         this. = length;
         this. = value;
     }
 
     public int getType() {
         return ;
     }
     
     public int getLength() {
         return ;
     }
 
     public byte[] getValue() {
         return ;
     }
 
     public boolean isConstructed() {
         return  ( & .) == .;
     }

    
For constructed field, return a parser for its content.

Returns:
A parser for the construct.
 
     public DerParser getParser() throws IOException {
         if (!isConstructed()) 
             throw new IOException("Invalid DER: can't parse primitive entity"); //$NON-NLS-1$
         
         return new DerParser();
     }
    
    
Get the value as integer
    public BigInteger getInteger() throws IOException {
        if ( != .)
            throw new IOException("Invalid DER: object is not integer"); //$NON-NLS-1$
        
        return new BigInteger();
    }
    
    
Get value as string. Most strings are treated as Latin-1.
    public String getString() throws IOException {
        String encoding;
        switch () {
        
        // Not all are Latin-1 but it's the closest thing
        case .:
        case .:
        case .:
        case .:
        case .:
        case .:
        case .:
            encoding = "ISO-8859-1"//$NON-NLS-1$
            break;
        case .:
            encoding = "UTF-16BE"//$NON-NLS-1$
            break;
        case .:
            encoding = "UTF-8"//$NON-NLS-1$
            break;
        case .:
            throw new IOException("Invalid DER: can't handle UCS-4 string"); //$NON-NLS-1$
        default:
            throw new IOException("Invalid DER: object is not a string"); //$NON-NLS-1$
        }
        return new String(encoding);
    }
New to GrepCode? Check out our FAQ X