1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
impl B64Encode<i32,String> for B64<String>{
    fn encode(data:i32)->String{
        let mut string:String=String::with_capacity(8);
        unsafe{
            let mut vector=&mut string.as_mut_vec();
            vector.resize(8,0);
            let pointer=vector.as_mut_ptr();
            let ptr_alphabet=ALPHABET64.as_ptr();
            *pointer.offset(0)=*ptr_alphabet.offset(((data>>26)&0b111111) as isize);
            *pointer.offset(1)=*ptr_alphabet.offset(((data>>20)&0b111111) as isize);
            *pointer.offset(2)=*ptr_alphabet.offset(((data>>14)&0b111111) as isize);
            *pointer.offset(3)=*ptr_alphabet.offset(((data>>08)&0b111111) as isize);
            *pointer.offset(4)=*ptr_alphabet.offset(((data>>02)&0b111111) as isize);
            *pointer.offset(5)=*ptr_alphabet.offset(((data<<04)&0b111111) as isize);
            *pointer.offset(6)=61;
            *pointer.offset(7)=61;
        }
        return string;
    }
}

impl<'a> B64Encode<&'a i32,String> for B64<String>{
    fn encode(data:&'a i32)->String{
        let mut string:String=String::with_capacity(8);
        unsafe{
            let mut vector=&mut string.as_mut_vec();
            vector.resize(8,0);
            let pointer=vector.as_mut_ptr();
            let ptr_alphabet=ALPHABET64.as_ptr();
            *pointer.offset(0)=*ptr_alphabet.offset(((*data>>26)&0b111111) as isize);
            *pointer.offset(1)=*ptr_alphabet.offset(((*data>>20)&0b111111) as isize);
            *pointer.offset(2)=*ptr_alphabet.offset(((*data>>14)&0b111111) as isize);
            *pointer.offset(3)=*ptr_alphabet.offset(((*data>>08)&0b111111) as isize);
            *pointer.offset(4)=*ptr_alphabet.offset(((*data>>02)&0b111111) as isize);
            *pointer.offset(5)=*ptr_alphabet.offset(((*data<<04)&0b111111) as isize);
            *pointer.offset(6)=61;
            *pointer.offset(7)=61;
        }
        return string;
    }
}

impl B64Decode<String,i32> for B64<i32>{
    fn decode(data:String)->i32{
        let mut n:u32=0;
        unsafe{
            let ptr_data=data.as_ptr();
            let ptr_alphabet=_ALPHABET64.as_ptr();
            n|=((*ptr_alphabet.offset((*ptr_data.offset(0)) as isize)) as u32)<<26;
            n|=((*ptr_alphabet.offset((*ptr_data.offset(1)) as isize)) as u32)<<20;
            n|=((*ptr_alphabet.offset((*ptr_data.offset(2)) as isize)) as u32)<<14;
            n|=((*ptr_alphabet.offset((*ptr_data.offset(3)) as isize)) as u32)<<08;
            n|=((*ptr_alphabet.offset((*ptr_data.offset(4)) as isize)) as u32)<<02;
            n|=((*ptr_alphabet.offset((*ptr_data.offset(5)) as isize)) as u32)>>04;
        }
        return n as i32;
    }
}

impl B64Decode<&'static str,i32> for B64<i32>{
    fn decode(data:&'static str)->i32{
        let mut n:u32=0;
        unsafe{
            let ptr_data=data.as_ptr();
            let ptr_alphabet=_ALPHABET64.as_ptr();
            n|=((*ptr_alphabet.offset((*ptr_data.offset(0)) as isize)) as u32)<<26;
            n|=((*ptr_alphabet.offset((*ptr_data.offset(1)) as isize)) as u32)<<20;
            n|=((*ptr_alphabet.offset((*ptr_data.offset(2)) as isize)) as u32)<<14;
            n|=((*ptr_alphabet.offset((*ptr_data.offset(3)) as isize)) as u32)<<08;
            n|=((*ptr_alphabet.offset((*ptr_data.offset(4)) as isize)) as u32)<<02;
            n|=((*ptr_alphabet.offset((*ptr_data.offset(5)) as isize)) as u32)>>04;
        }
        return n as i32;
    }
}