1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.crypto.internal.encoder

File Base64BinaryStringEncoder.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
2
2
1
64
26
2
1
1
2
1

Classes

Class Line # Actions
Base64BinaryStringEncoder 37 2 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 8 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.crypto.internal.encoder;
21   
22    import javax.inject.Named;
23    import javax.inject.Singleton;
24   
25    import org.bouncycastle.util.encoders.Base64Encoder;
26    import org.xwiki.component.annotation.Component;
27   
28    /**
29    * Encoder/Decoder of base64 data.
30    *
31    * @version $Id: 3d07dd703c951105bfb771401540fd4d42e23a82 $
32    * @since 5.4M1
33    */
34    @Component
35    @Singleton
36    @Named("Base64")
 
37    public class Base64BinaryStringEncoder extends AbstractBinaryStringEncoder
38    {
39    /**
40    * Number of bytes of binary data that should be encoded together.
41    * Base64 encode 3 bytes into 4 chars.
42    */
43    protected static final int BLOCK_SIZE = 3;
44   
45    /**
46    * Number of bytes of string data that should be decoded together.
47    * Base64 decode 4 chars into 3 bytes.
48    */
49    protected static final int CHAR_SIZE = 4;
50   
 
51  106 toggle @Override
52    InternalBinaryStringEncoder getEncoder()
53    {
54  106 return new AbstractBouncyCastleInternalBinaryStringEncoder(new Base64Encoder(), BLOCK_SIZE, CHAR_SIZE)
55    {
 
56  864 toggle @Override
57    public boolean isValidEncoding(byte b)
58    {
59  864 return (b == 0x2b || b == 0x3d || (b >= 0x2f && b <= 0x39)
60    || (b >= 0x41 && b <= 0x5a) || (b >= 0x61 && b <= 0x7a));
61    }
62    };
63    }
64    }