@@ -20,6 +20,9 @@ public class Configuration {
2020 public final static String VERSION = "1.0.2" ;
2121 public final static String USER_AGENT = "cld-android-" + VERSION ;
2222 public static final boolean DEFAULT_IS_LONG_SIGNATURE = false ;
23+ public static final SignatureAlgorithm DEFAULT_SIGNATURE_ALGORITHM = SignatureAlgorithm .SHA1 ;
24+
25+ private static final String CONFIG_PROP_SIGNATURE_ALGORITHM = "signature_algorithm" ;
2326
2427 public String cloudName ;
2528 public String apiKey ;
@@ -43,11 +46,32 @@ public class Configuration {
4346 public AuthToken authToken ;
4447 public boolean forceVersion = true ;
4548 public boolean longUrlSignature = DEFAULT_IS_LONG_SIGNATURE ;
49+ public SignatureAlgorithm signatureAlgorithm = DEFAULT_SIGNATURE_ALGORITHM ;
4650
4751 public Configuration () {
4852 }
4953
50- private Configuration (String cloudName , String apiKey , String apiSecret , String secureDistribution , String cname , String uploadPrefix , boolean secure , boolean privateCdn , boolean cdnSubdomain , boolean shorten , String callback , String proxyHost , int proxyPort , Boolean secureCdnSubdomain , boolean useRootPath , int timeout , boolean loadStrategies , boolean forceVersion , boolean longUrlSignature ) {
54+ private Configuration (
55+ String cloudName ,
56+ String apiKey ,
57+ String apiSecret ,
58+ String secureDistribution ,
59+ String cname ,
60+ String uploadPrefix ,
61+ boolean secure ,
62+ boolean privateCdn ,
63+ boolean cdnSubdomain ,
64+ boolean shorten ,
65+ String callback ,
66+ String proxyHost ,
67+ int proxyPort ,
68+ Boolean secureCdnSubdomain ,
69+ boolean useRootPath ,
70+ int timeout ,
71+ boolean loadStrategies ,
72+ boolean forceVersion ,
73+ boolean longUrlSignature ,
74+ SignatureAlgorithm signatureAlgorithm ) {
5175 this .cloudName = cloudName ;
5276 this .apiKey = apiKey ;
5377 this .apiSecret = apiSecret ;
@@ -67,6 +91,7 @@ private Configuration(String cloudName, String apiKey, String apiSecret, String
6791 this .loadStrategies = loadStrategies ;
6892 this .forceVersion = forceVersion ;
6993 this .longUrlSignature = longUrlSignature ;
94+ this .signatureAlgorithm = signatureAlgorithm ;
7095 }
7196
7297 @ SuppressWarnings ("rawtypes" )
@@ -104,6 +129,7 @@ public void update(Map config) {
104129 this .properties .putAll (properties );
105130 }
106131 this .longUrlSignature = ObjectUtils .asBoolean (config .get ("long_url_signature" ), DEFAULT_IS_LONG_SIGNATURE );
132+ this .signatureAlgorithm = SignatureAlgorithm .valueOf (ObjectUtils .asString (config .get (CONFIG_PROP_SIGNATURE_ALGORITHM ), DEFAULT_SIGNATURE_ALGORITHM .name ()));
107133 }
108134
109135 @ SuppressWarnings ("rawtypes" )
@@ -133,6 +159,7 @@ public Map<String, Object> asMap() {
133159 map .put ("force_version" , forceVersion );
134160 map .put ("properties" , new HashMap <String ,Object >(properties ));
135161 map .put ("long_url_signature" , longUrlSignature );
162+ map .put (CONFIG_PROP_SIGNATURE_ALGORITHM , signatureAlgorithm .toString ());
136163 return map ;
137164 }
138165
@@ -162,6 +189,7 @@ public Configuration(Configuration other) {
162189 this .loadStrategies = other .loadStrategies ;
163190 this .properties .putAll (other .properties );
164191 this .longUrlSignature = other .longUrlSignature ;
192+ this .signatureAlgorithm = other .signatureAlgorithm ;
165193 }
166194
167195 /**
@@ -272,6 +300,7 @@ public static class Builder {
272300 private AuthToken authToken ;
273301 private boolean forceVersion = true ;
274302 private boolean longUrlSignature = DEFAULT_IS_LONG_SIGNATURE ;
303+ private SignatureAlgorithm signatureAlgorithm = DEFAULT_SIGNATURE_ALGORITHM ;
275304
276305 /**
277306 * Set the HTTP connection timeout.
@@ -288,7 +317,27 @@ public Builder setTimeout(int timeout) {
288317 * Creates a {@link Configuration} with the arguments supplied to this builder
289318 */
290319 public Configuration build () {
291- final Configuration configuration = new Configuration (cloudName , apiKey , apiSecret , secureDistribution , cname , uploadPrefix , secure , privateCdn , cdnSubdomain , shorten , callback , proxyHost , proxyPort , secureCdnSubdomain , useRootPath , timeout , loadStrategies , forceVersion , longUrlSignature );
320+ final Configuration configuration = new Configuration (
321+ cloudName ,
322+ apiKey ,
323+ apiSecret ,
324+ secureDistribution ,
325+ cname ,
326+ uploadPrefix ,
327+ secure ,
328+ privateCdn ,
329+ cdnSubdomain ,
330+ shorten ,
331+ callback ,
332+ proxyHost ,
333+ proxyPort ,
334+ secureCdnSubdomain ,
335+ useRootPath ,
336+ timeout ,
337+ loadStrategies ,
338+ forceVersion ,
339+ longUrlSignature ,
340+ signatureAlgorithm );
292341 configuration .clientHints = clientHints ;
293342 return configuration ;
294343 }
@@ -412,6 +461,11 @@ public Builder setIsLongUrlSignature(boolean isLong) {
412461 return this ;
413462 }
414463
464+ public Builder setSignatureAlgorithm (SignatureAlgorithm signatureAlgorithm ) {
465+ this .signatureAlgorithm = signatureAlgorithm ;
466+ return this ;
467+ }
468+
415469 /**
416470 * Initialize builder from existing {@link Configuration}
417471 *
@@ -440,6 +494,7 @@ public Builder from(Configuration other) {
440494 this .authToken = other .authToken == null ? null : other .authToken .copy ();
441495 this .forceVersion = other .forceVersion ;
442496 this .longUrlSignature = other .longUrlSignature ;
497+ this .signatureAlgorithm = other .signatureAlgorithm ;
443498 return this ;
444499 }
445500 }
0 commit comments