Package org.apache.directory.shared.asn1.ber.tlv

Examples of org.apache.directory.shared.asn1.ber.tlv.BerValue


            SyncStateValueStatesEnum.SYNC_TYPE_STATE, UniversalTag.ENUMERATED.getValue(),
            new GrammarAction<SyncStateValueContainer>( "Set SyncStateValueControl state type" )
            {
                public void action( SyncStateValueContainer container ) throws DecoderException
                {
                    BerValue value = container.getCurrentTLV().getValue();

                    try
                    {
                        // Check that the value is into the allowed interval
                        int syncStateType = IntegerDecoder.parse( value, SyncStateTypeEnum.PRESENT.getValue(),
                            SyncStateTypeEnum.MODDN.getValue() );

                        SyncStateTypeEnum syncStateTypeEnum = SyncStateTypeEnum.getSyncStateType( syncStateType );

                        if ( IS_DEBUG )
                        {
                            LOG.debug( "SyncStateType = {}", syncStateTypeEnum );
                        }

                        container.getSyncStateValueControl().setSyncStateType( syncStateTypeEnum );

                        // move on to the entryUUID transition
                        container.setGrammarEndAllowed( false );
                    }
                    catch ( IntegerDecoderException e )
                    {
                        String msg = I18n.err( I18n.ERR_04030 );
                        LOG.error( msg, e );
                        throw new DecoderException( msg );
                    }
                }
            } );

        /**
         * Transition from sync state tpe to entryUUID
         * SyncStateValue ::= SEQUENCE OF {
         *     ...
         *     entryUUID     syncUUID
         *     ...
         *    
         * Stores the entryUUID
         */
        super.transitions[SyncStateValueStatesEnum.SYNC_TYPE_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition<SyncStateValueContainer>(
            SyncStateValueStatesEnum.SYNC_TYPE_STATE, SyncStateValueStatesEnum.SYNC_UUID_STATE,
            UniversalTag.OCTET_STRING.getValue(),
            new GrammarAction<SyncStateValueContainer>( "Set SyncStateValueControl entryUUID" )
            {
                public void action( SyncStateValueContainer container ) throws DecoderException
                {
                    BerValue value = container.getCurrentTLV().getValue();

                    byte[] entryUUID = value.getData();

                    if ( IS_DEBUG )
                    {
                        LOG.debug( "entryUUID = {}", Strings.dumpBytes( entryUUID ) );
                    }

                    container.getSyncStateValueControl().setEntryUUID( entryUUID );

                    // We can have an END transition
                    container.setGrammarEndAllowed( true );
                }
            } );

        /**
         * Transition from entryUUID to cookie
         * SyncRequestValue ::= SEQUENCE OF {
         *     ...
         *     cookie    syncCookie OPTIONAL
         * }
         *    
         * Stores the reloadHint flag
         */
        super.transitions[SyncStateValueStatesEnum.SYNC_UUID_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition<SyncStateValueContainer>(
            SyncStateValueStatesEnum.SYNC_UUID_STATE, SyncStateValueStatesEnum.COOKIE_STATE,
            UniversalTag.OCTET_STRING.getValue(),
            new GrammarAction<SyncStateValueContainer>( "Set SyncStateValueControl cookie value" )
            {
                public void action( SyncStateValueContainer container ) throws DecoderException
                {
                    BerValue value = container.getCurrentTLV().getValue();

                    byte[] cookie = value.getData();

                    if ( IS_DEBUG )
                    {
                        LOG.debug( "cookie = {}", cookie );
                    }
View Full Code Here


        for ( int i:testedInt )
        {
            encoded = new BigInteger( Integer.toString( i ) ).toByteArray();

            int value = IntegerDecoder.parse( new BerValue( encoded ) );

            assertEquals( i, value );
        }
    }
View Full Code Here

        for ( long i:testedLong )
        {
            encoded = new BigInteger( Long.toString( i ) ).toByteArray();

            long value = LongDecoder.parse( new BerValue( encoded ) );

            assertEquals( i, value );
        }
    }
View Full Code Here

    @Test
    public void testNewByteArrayValue()
    {
        byte[] bb = new byte[]{0x01, (byte)0xFF};
       
        BerValue v = new BerValue( bb );
        byte[] vv = v.getData();
       
        assertEquals( 0x01, vv[0] );
        assertEquals( (byte)0xFF, vv[1] );
       
        bb[0] = 0x00;
View Full Code Here

                if ( type.equals( "int" ) )
                {
                    try
                    {
                        return IntegerDecoder.parse( new BerValue( ( byte[] ) obj ) );
                    }
                    catch ( IntegerDecoderException e )
                    {
                        throw new RuntimeException( "Failed to decode INTEGER: " +
                            Strings.dumpBytes( ( byte[] ) obj ), e );
View Full Code Here

                UniversalTag.INTEGER.getValue(),
                new GrammarAction<PagedResultsContainer>( "Set PagedSearchControl size" )
                {
                    public void action( PagedResultsContainer container ) throws DecoderException
                    {
                        BerValue value = container.getCurrentTLV().getValue();

                        try
                        {
                            // Check that the value is into the allowed interval
                            int size = IntegerDecoder.parse( value, Integer.MIN_VALUE, Integer.MAX_VALUE );

                            // We allow negative value to absorb a bug in some M$ client.
                            // Those negative values will be transformed to Integer.MAX_VALUE.
                            if ( size < 0 )
                            {
                                size = Integer.MAX_VALUE;
                            }

                            if ( IS_DEBUG )
                            {
                                LOG.debug( "size = " + size );
                            }

                            container.getDecorator().setSize( size );
                        }
                        catch ( IntegerDecoderException e )
                        {
                            String msg = I18n.err( I18n.ERR_04050 );
                            LOG.error( msg, e );
                            throw new DecoderException( msg );
                        }
                    }
                } );

        /**
         * Transition from size to cookie
         * realSearchControlValue ::= SEQUENCE OF {
         *     ...
         *     cookie   OCTET STRING
         * }
         *    
         * Stores the cookie flag
         */
        super.transitions[PagedResultsStates.SIZE_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
            new GrammarTransition<PagedResultsContainer>( PagedResultsStates.SIZE_STATE,
                PagedResultsStates.COOKIE_STATE, UniversalTag.OCTET_STRING.getValue(),
                new GrammarAction<PagedResultsContainer>( "Set PagedSearchControl cookie" )
                {
                    public void action( PagedResultsContainer container ) throws DecoderException
                    {
                        BerValue value = container.getCurrentTLV().getValue();

                        if ( container.getCurrentTLV().getLength() == 0 )
                        {
                            container.getDecorator().setCookie( StringConstants.EMPTY_BYTES );
                        }
                        else
                        {
                            container.getDecorator().setCookie( value.getData() );
                        }

                        // We can have an END transition
                        container.setGrammarEndAllowed( true );
                    }
View Full Code Here

            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
        }

        Checksum checksum = checksumContainer.getChecksum();
        // The Checksum's type is an integer
        BerValue value = tlv.getValue();

        try
        {
            int cksumType = IntegerDecoder.parse( value );

            checksum.setChecksumType( ChecksumType.getTypeByValue( cksumType ) );

            if ( IS_DEBUG )
            {
                LOG.debug( "cksumType : " + cksumType );
            }
        }
        catch ( IntegerDecoderException ide )
        {
            LOG.error( I18n.err( I18n.ERR_04070, Strings.dumpBytes( value.getData() ), ide
                .getLocalizedMessage() ) );

            // This will generate a PROTOCOL_ERROR
            throw new DecoderException( ide.getMessage() );
        }
View Full Code Here

        }

        // Get the principalName
        PrincipalName principalName = principalNameContainer.getPrincipalName();

        BerValue value = tlv.getValue();

        // The PrincipalName must be pure ASCII witout any control character
        if ( KerberosUtils.isKerberosString( value.getData() ) )
        {
            String nameString = Strings.utf8ToString( value.getData() );

            principalName.addName( nameString );
            principalNameContainer.setGrammarEndAllowed( true );

            if ( IS_DEBUG )
            {
                LOG.debug( "PrincipalName String : {}", nameString );
            }
        }
        else
        {
            String valBytes = Strings.dumpBytes( value.getData() );
            String valStr = Strings.utf8ToString( value.getData() );
            String valAll = valBytes + "/" + valStr;
            LOG.error( I18n.err( I18n.ERR_745_NOT_A_KERBEROS_STRING, valAll ) );

            // This will generate a PROTOCOL_ERROR
            throw new DecoderException( I18n.err( I18n.ERR_745_NOT_A_KERBEROS_STRING, valAll ) );
View Full Code Here

            // This will generate a PROTOCOL_ERROR
            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
        }

        // The etype is an integer
        BerValue value = tlv.getValue();

        EncryptionType etype = null;
        ETypeInfoEntry etypeInfoEntry = eTypeInfoEntryContainer.getETypeInfoEntry();

        try
        {
            int eType = IntegerDecoder.parse( value );
            etype = EncryptionType.getTypeByValue( eType );

            etypeInfoEntry.setEType( etype );

            if ( IS_DEBUG )
            {
                LOG.debug( "etype : " + etype );
            }

            // The next tag is optional, we can end here
            eTypeInfoEntryContainer.setGrammarEndAllowed( true );
        }
        catch ( IntegerDecoderException ide )
        {
            LOG.error( I18n.err( I18n.ERR_04070, Strings.dumpBytes( value.getData() ), ide
                .getLocalizedMessage() ) );

            // This will generate a PROTOCOL_ERROR
            throw new DecoderException( ide.getMessage() );
        }
View Full Code Here

            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
        }

        PaData paData = paDataContainer.getPaData();
        // The PaData's type is an integer
        BerValue value = tlv.getValue();

        try
        {
            int paDataType = IntegerDecoder.parse( value );

            paData.setPaDataType( PaDataType.getTypeByValue( paDataType ) );

            if ( IS_DEBUG )
            {
                LOG.debug( "padata-type : {}", paDataType );
            }
        }
        catch ( IntegerDecoderException ide )
        {
            LOG.error( I18n.err( I18n.ERR_04070, Strings.dumpBytes( value.getData() ), ide
                .getLocalizedMessage() ) );

            // This will generate a PROTOCOL_ERROR
            throw new DecoderException( ide.getMessage() );
        }
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.asn1.ber.tlv.BerValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.