Example #1
0
size_t base64_decode_block(const char* code_in, const size_t length_in, char* plaintext_out, base64_decodestate* state_in){
    const char* codechar = code_in;
    char* plainchar = plaintext_out;
    char fragment;
    
    *plainchar = state_in->plainchar;
    
    switch (state_in->step){
        while (1){
            case step_a:
                do{
                    if (codechar == code_in+length_in){
                        state_in->step = step_a;
                        state_in->plainchar = *plainchar;
                        return plainchar - plaintext_out;
                    }
                    fragment = (char)base64_decode_value(*codechar++);
                } while ((signed char)fragment < 0);
                *plainchar = (fragment & 0x03f) << 2;

            case step_b:
                do{
                    if (codechar == code_in+length_in){
                        state_in->step = step_b;
                        state_in->plainchar = *plainchar;
                        return plainchar - plaintext_out;
                    }
                    fragment = (char)base64_decode_value(*codechar++);
                } while ((signed char)fragment < 0);
                *plainchar++ |= (fragment & 0x030) >> 4;
                *plainchar    = (fragment & 0x00f) << 4;
            case step_c:
                do{
                    if (codechar == code_in+length_in)
                    {
                        state_in->step = step_c;
                        state_in->plainchar = *plainchar;
                        return plainchar - plaintext_out;
                    }
                    fragment = (char)base64_decode_value(*codechar++);
                } while ((signed char)fragment < 0);
                *plainchar++ |= (fragment & 0x03c) >> 2;
                *plainchar    = (fragment & 0x003) << 6;
            case step_d:
                do{
                    if (codechar == code_in+length_in){
                        state_in->step = step_d;
                        state_in->plainchar = *plainchar;
                        return plainchar - plaintext_out;
                    }
                    fragment = (char)base64_decode_value(*codechar++);
                } while ((signed char)fragment < 0);
                *plainchar++   |= (fragment & 0x03f);
        }
    }
    /* control should not reach here */
    return plainchar - plaintext_out;
}
Example #2
0
static HB_SIZE base64_decode_block( const char * code_in, const HB_SIZE length_in, char * pszPlainttextOut )
{
   const char * codechar     = code_in;
   const char * code_end     = code_in + length_in;
   char *       pszPlainchar = pszPlainttextOut;
   signed char  fragment;

   for(;; )
   {
      do
      {
         if( codechar == code_end )
            return pszPlainchar - pszPlainttextOut;
         fragment = base64_decode_value( *codechar++ );
      }
      while( fragment < 0 );
      *pszPlainchar = ( fragment & 0x03F ) << 2;

      do
      {
         if( codechar == code_end )
            return pszPlainchar - pszPlainttextOut;
         fragment = base64_decode_value( *codechar++ );
      }
      while( fragment < 0 );
      *pszPlainchar++ |= ( fragment & 0x030 ) >> 4;
      *pszPlainchar    = ( fragment & 0x00F ) << 4;

      do
      {
         if( codechar == code_end )
            return pszPlainchar - pszPlainttextOut;
         fragment = base64_decode_value( *codechar++ );
      }
      while( fragment < 0 );
      *pszPlainchar++ |= ( fragment & 0x03C ) >> 2;
      *pszPlainchar    = ( fragment & 0x003 ) << 6;

      do
      {
         if( codechar == code_end )
            return pszPlainchar - pszPlainttextOut;
         fragment = base64_decode_value( *codechar++ );
      }
      while( fragment < 0 );
      *pszPlainchar++ |= ( fragment & 0x03F );
   }
}
Example #3
0
static int
base64_decode_block(const char *in_base64, int in_len,
		    char *out_bin, int out_len,
		    struct base64_decodestate *state)
{
	const char *in_pos = in_base64;
	const char *in_end = in_base64 + in_len;
	char *out_pos = out_bin;
	char *out_end = out_bin + out_len;
	int fragment;

	*out_pos = state->result;

	switch (state->step)
	{
		while (1)
		{
	case step_a:
			do {
				if (in_pos == in_end || out_pos >= out_end)
				{
					state->step = step_a;
					state->result = *out_pos;
					return out_pos - out_bin;
				}
				fragment = base64_decode_value(*in_pos++);
			} while (fragment < 0);
			*out_pos    = (fragment & 0x03f) << 2;
	case step_b:
			do {
				if (in_pos == in_end || out_pos >= out_end)
				{
					state->step = step_b;
					state->result = *out_pos;
					return out_pos - out_bin;
				}
				fragment = base64_decode_value(*in_pos++);
			} while (fragment < 0);
			*out_pos++ |= (fragment & 0x030) >> 4;
			if (out_pos < out_end)
				*out_pos = (fragment & 0x00f) << 4;
	case step_c:
			do {
				if (in_pos == in_end || out_pos >= out_end)
				{
					state->step = step_c;
					state->result = *out_pos;
					return out_pos - out_bin;
				}
				fragment = base64_decode_value(*in_pos++);
			} while (fragment < 0);
			*out_pos++ |= (fragment & 0x03c) >> 2;
			if (out_pos < out_end)
				*out_pos = (fragment & 0x003) << 6;
	case step_d:
			do {
				if (in_pos == in_end || out_pos >= out_end)
				{
					state->step = step_d;
					state->result = *out_pos;
					return out_pos - out_bin;
				}
				fragment = base64_decode_value(*in_pos++);
			} while (fragment < 0);
			*out_pos++   |= (fragment & 0x03f);
		}
	}
	/* control should not reach here */
	return out_pos - out_bin;
}
Example #4
0
		int decode(char value_in)
		{
			return base64_decode_value(value_in);
		}
int Base64decoder::decode(char value_in)
{
    return base64_decode_value(value_in);
}