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

File RC5CBCParameter.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

12
29
10
1
176
82
16
0.55
2.9
10
1.6

Classes

Class Line # Actions
RC5CBCParameter 43 29 0% 16 51
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.password.internal.pbe;
21   
22    import java.math.BigInteger;
23   
24    import org.bouncycastle.asn1.ASN1EncodableVector;
25    import org.bouncycastle.asn1.ASN1Integer;
26    import org.bouncycastle.asn1.ASN1Object;
27    import org.bouncycastle.asn1.ASN1OctetString;
28    import org.bouncycastle.asn1.ASN1Primitive;
29    import org.bouncycastle.asn1.ASN1Sequence;
30    import org.bouncycastle.asn1.DEROctetString;
31    import org.bouncycastle.asn1.DERSequence;
32   
33    /**
34    * RC5-CBC-Pad encryption parameters as defined in rfc-2898.
35    *
36    * WARNING: RSA Security own the US Patent US5724428 A on this algorithm. Therefore, before expiration of this patent,
37    * which will happen in november 2015, the usage of this algorithm is subject to restricted usage on the US territories.
38    * RC5 is a registered trademark of RSA Security.
39    *
40    * @version $Id: 945a70bc44ce953595aec1163f758e76c42ac62e $
41    * @since 5.4M1
42    */
 
43    public class RC5CBCParameter extends ASN1Object
44    {
45    private ASN1Integer version;
46   
47    private ASN1Integer rounds;
48   
49    private ASN1Integer blockSizeInBits;
50   
51    private ASN1OctetString iv;
52   
53    /**
54    * Create a new instance without the optional initialization vector.
55    *
56    * @param rounds the number of "rounds" in the encryption operation between 8 and 127.
57    * @param blockSizeInBits the block size in bits, may be 64 or 128.
58    */
 
59  0 toggle public RC5CBCParameter(int rounds, int blockSizeInBits)
60    {
61  0 this(16, rounds, blockSizeInBits, null);
62    }
63   
64    /**
65    * Create a new instance with the optional initialization vector.
66    *
67    * @param rounds the number of "rounds" in the encryption operation between 8 and 127.
68    * @param blockSizeInBits the block size in bits, may be 64 or 128.
69    * @param iv the initialization vector.
70    */
 
71  0 toggle public RC5CBCParameter(int rounds, int blockSizeInBits, byte[] iv)
72    {
73  0 this(16, rounds, blockSizeInBits, iv);
74    }
75   
76    /**
77    * Create a new instance with the optional initialization vector and a specific parameter version.
78    *
79    * @param parameterVersion the version of this parameter structure, should be v1-0 (16).
80    * @param rounds the number of "rounds" in the encryption operation between 8 and 127.
81    * @param blockSizeInBits the block size in bits, may be 64 or 128.
82    * @param iv the initialization vector.
83    */
 
84  0 toggle public RC5CBCParameter(int parameterVersion, int rounds, int blockSizeInBits, byte[] iv)
85    {
86  0 this.version = new ASN1Integer(parameterVersion);
87  0 this.rounds = new ASN1Integer(rounds);
88  0 this.blockSizeInBits = new ASN1Integer(blockSizeInBits);
89  0 this.iv = (iv != null) ? new DEROctetString(iv) : null;
90    }
91   
92    /**
93    * Create a new instance from a ASN.1 sequence.
94    *
95    * @param seq the ASN.1 sequence to parse.
96    */
 
97  0 toggle private RC5CBCParameter(ASN1Sequence seq)
98    {
99  0 this.version = (ASN1Integer) seq.getObjectAt(0);
100  0 this.rounds = (ASN1Integer) seq.getObjectAt(1);
101  0 this.blockSizeInBits = (ASN1Integer) seq.getObjectAt(2);
102  0 if (seq.size() > 3) {
103  0 this.iv = (ASN1OctetString) seq.getObjectAt(3);
104    }
105    }
106   
107    /**
108    * Get an instance from an ASN.1 object.
109    *
110    * @param obj an ASN.1 object.
111    * @return an instance.
112    */
 
113  0 toggle public static RC5CBCParameter getInstance(Object obj)
114    {
115  0 if (obj instanceof RC5CBCParameter) {
116  0 return (RC5CBCParameter) obj;
117    }
118  0 if (obj != null) {
119  0 return new RC5CBCParameter(ASN1Sequence.getInstance(obj));
120    }
121  0 return null;
122    }
123   
124    /**
125    * @return the version of this parameter structure.
126    */
 
127  0 toggle public BigInteger getRC5ParameterVersion()
128    {
129  0 return this.version.getValue();
130    }
131   
132    /**
133    * @return the number of "rounds" in the encryption operation between 8 and 127.
134    */
 
135  0 toggle public BigInteger getRounds()
136    {
137  0 return this.rounds.getValue();
138    }
139   
140    /**
141    * @return the block size in bits, may be 64 or 128.
142    */
 
143  0 toggle public BigInteger getBlockSizeInBits()
144    {
145  0 return this.blockSizeInBits.getValue();
146    }
147   
148    /**
149    * @return the initialization vector.
150    */
 
151  0 toggle public byte[] getIV()
152    {
153  0 if (this.iv == null) {
154  0 return null;
155    }
156  0 return this.iv.getOctets();
157    }
158   
159    /**
160    * @return an ASN.1 structure representing these parameters.
161    */
 
162  0 toggle @Override
163    public ASN1Primitive toASN1Primitive()
164    {
165  0 ASN1EncodableVector v = new ASN1EncodableVector();
166   
167  0 v.add(this.version);
168  0 v.add(this.rounds);
169  0 v.add(this.blockSizeInBits);
170  0 if (this.iv != null) {
171  0 v.add(this.iv);
172    }
173   
174  0 return new DERSequence(v);
175    }
176    }