55import com .google .gson .JsonObject ;
66import com .google .gson .JsonPrimitive ;
77
8+ import java .util .ArrayList ;
89import java .util .List ;
910import java .util .Objects ;
1011
1415public class AuthorizationList {
1516 private final List <Purpose > purposeList ;
1617 private final Algorithm algorithm ;
18+ private final Integer keySize ;
19+ private final List <BlockMode > blockModeList ;
1720
1821 @ VisibleForTesting
1922 public static final String JSON_ALGORITHM_KEY = "algorithm" ;
20-
2123 @ VisibleForTesting
2224 public static final String JSON_PURPOSE_KEY = "purpose" ;
25+ @ VisibleForTesting
26+ public static final String JSON_KEY_SIZE_KEY = "keysize" ;
27+ @ VisibleForTesting
28+ public static final String JSON_BLOCK_MODE_KEY = "blockmode" ;
2329
24- protected AuthorizationList (List <Purpose > purpose , Algorithm algorithm ) {
25- this .purposeList = purpose ;
30+ protected AuthorizationList (List <Purpose > purposeList , Algorithm algorithm , Integer keySize ,
31+ List <BlockMode > blockModeList ) {
32+ this .purposeList = purposeList ;
2633 this .algorithm = algorithm ;
34+ this .keySize = keySize ;
35+ this .blockModeList = blockModeList ;
2736 }
2837
29- public List <Purpose > getPurpose () {
38+ public List <Purpose > getPurposeList () {
3039 return purposeList ;
3140 }
3241
3342 public Algorithm getAlgorithm () {
3443 return algorithm ;
3544 }
3645
46+ public Integer getKeySize () {
47+ return keySize ;
48+ }
49+
50+ public List <BlockMode > getBlockModeList () {
51+ return blockModeList ;
52+ }
53+
3754 @ Override
3855 public int hashCode () {
39- return Objects .hash (purposeList , algorithm );
56+ return Objects .hash (purposeList , algorithm , keySize , blockModeList );
4057 }
4158
4259 @ Override
@@ -50,7 +67,9 @@ public boolean equals(Object obj) {
5067
5168 AuthorizationList other = (AuthorizationList ) obj ;
5269 return Objects .equals (algorithm , other .algorithm )
53- && Objects .equals (purposeList , other .purposeList );
70+ && areEqualIgnoringOrder (purposeList , other .purposeList )
71+ && Objects .equals (keySize , other .keySize )
72+ && areEqualIgnoringOrder (blockModeList , other .blockModeList );
5473 }
5574
5675 @ Override
@@ -59,7 +78,7 @@ public String toString() {
5978 stringRepresentation .append ("[" );
6079
6180 if (purposeList != null ) {
62- stringRepresentation .append ("\n purpose: " );
81+ stringRepresentation .append ("\n purpose list : " );
6382 stringRepresentation .append (purposeList );
6483 }
6584
@@ -68,6 +87,16 @@ public String toString() {
6887 stringRepresentation .append (algorithm );
6988 }
7089
90+ if (keySize != null ) {
91+ stringRepresentation .append ("\n key size: " );
92+ stringRepresentation .append (keySize );
93+ }
94+
95+ if (blockModeList != null ) {
96+ stringRepresentation .append ("\n block mode list: " );
97+ stringRepresentation .append (blockModeList );
98+ }
99+
71100 stringRepresentation .append ("\n ]" );
72101
73102 return stringRepresentation .toString ();
@@ -77,28 +106,44 @@ public JsonObject toJson() {
77106 JsonObject json = new JsonObject ();
78107 if (purposeList != null ) {
79108 JsonArray purposeJsonArray = new JsonArray ();
80- for (Purpose p : purposeList ) {
81- purposeJsonArray .add (new JsonPrimitive (p .toString ()));
109+ for (Purpose purpose : purposeList ) {
110+ purposeJsonArray .add (new JsonPrimitive (purpose .toString ()));
82111 }
83112 json .add (JSON_PURPOSE_KEY , purposeJsonArray );
84113 }
85114 if (algorithm != null ) {
86115 json .addProperty (JSON_ALGORITHM_KEY , algorithm .toString ());
87116 }
117+ if (keySize != null ) {
118+ json .addProperty (JSON_KEY_SIZE_KEY , keySize );
119+ }
120+ if (blockModeList != null ) {
121+ JsonArray blockModeJsonArray = new JsonArray ();
122+ for (BlockMode blockMode : blockModeList ) {
123+ blockModeJsonArray .add (new JsonPrimitive (blockMode .toString ()));
124+ }
125+ json .add (JSON_BLOCK_MODE_KEY , blockModeJsonArray );
126+ }
88127 return json ;
89128 }
90129
91130 public static class Builder {
92131 private List <Purpose > purpose ;
93132 private Algorithm algorithm ;
133+ private Integer keySize ;
134+ private List <BlockMode > blockMode ;
94135
95136 public Builder () {
96137 this .purpose = null ;
97138 this .algorithm = null ;
139+ this .keySize = null ;
140+ this .blockMode = null ;
98141 }
99142
100143 public Builder setPurpose (List <Purpose > purpose ) {
101- this .purpose = purpose ;
144+ if (purpose != null ) {
145+ this .purpose = new ArrayList <Purpose >(purpose );
146+ }
102147 return this ;
103148 }
104149
@@ -107,8 +152,28 @@ public Builder setAlgorithm(Algorithm algorithm) {
107152 return this ;
108153 }
109154
155+ public Builder setKeySize (Integer keySize ) {
156+ this .keySize = keySize ;
157+ return this ;
158+ }
159+
160+ public Builder setBlockMode (List <BlockMode > blockMode ) {
161+ if (blockMode != null ) {
162+ this .blockMode = new ArrayList <BlockMode >(blockMode );
163+ }
164+ return this ;
165+ }
166+
110167 public AuthorizationList build () {
111- return new AuthorizationList (this .purpose , this .algorithm );
168+ return new AuthorizationList (this .purpose , this .algorithm , this .keySize , this .blockMode );
169+ }
170+ }
171+
172+ private <T > boolean areEqualIgnoringOrder (List <T > list1 , List <T > list2 ) {
173+ if (list1 != null && list2 != null ) {
174+ return list1 .containsAll (list2 ) && list2 .containsAll (list1 );
112175 }
176+
177+ return list1 == null && list2 == null ;
113178 }
114179}
0 commit comments