Passed
Push — v6 ( 20d195...68f5c0 )
by 光春
03:59
created
src/service/ksyun/bin/samples/TestEncryptionClientMeta.php 3 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -16,37 +16,37 @@  discard block
 block discarded – undo
16 16
 multipartUpload($client,$bucket,$keyprefix);
17 17
 
18 18
 function putObjectByContentAndGetObjectUsingMeta($client,$bucket,$keyprefix){
19
-	for($i = 45 ;$i < 60;$i++){
19
+    for($i = 45 ;$i < 60;$i++){
20 20
 
21
-		$content = EncryptionUtil::genereateOnceUsedKey($i);
21
+        $content = EncryptionUtil::genereateOnceUsedKey($i);
22 22
 
23
-		$args = array(
24
-			"Bucket"=>$bucket,
25
-			"Key"=>$keyprefix."EOMeta",
26
-			"ACL"=>"public-read",
27
-			"Content"=>$content
28
-		);
29
-		$client->putObjectByContent($args);
30
-		rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOMeta",
31
-			"D://testdown/down",base64_encode(md5($args["Content"])));
32
-	}
23
+        $args = array(
24
+            "Bucket"=>$bucket,
25
+            "Key"=>$keyprefix."EOMeta",
26
+            "ACL"=>"public-read",
27
+            "Content"=>$content
28
+        );
29
+        $client->putObjectByContent($args);
30
+        rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOMeta",
31
+            "D://testdown/down",base64_encode(md5($args["Content"])));
32
+    }
33 33
 }
34 34
 function putObjectByFileAndGetObjectUsingMeta($client,$bucket,$keyprefix){
35 35
 
36
-	$args = array(
37
-		"Bucket"=>$bucket,
38
-		"Key"=>$keyprefix."EOMeta",
39
-		"ACL"=>"public-read",
40
-		"Content"=>array(
41
-			"content"=>"D://IMG.jpg"
42
-			)
43
-	);
44
-	$client->putObjectByFile($args);
45
-	rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOMeta",
46
-			"D://testdown/down",base64_encode(md5_file("D://IMG.jpg")));
36
+    $args = array(
37
+        "Bucket"=>$bucket,
38
+        "Key"=>$keyprefix."EOMeta",
39
+        "ACL"=>"public-read",
40
+        "Content"=>array(
41
+            "content"=>"D://IMG.jpg"
42
+            )
43
+    );
44
+    $client->putObjectByFile($args);
45
+    rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOMeta",
46
+            "D://testdown/down",base64_encode(md5_file("D://IMG.jpg")));
47 47
 }
48 48
 function multipartUpload($client,$bucket,$keyprefix){
49
-	//初始化分开上传,获取uploadid
49
+    //初始化分开上传,获取uploadid
50 50
     $args = array(
51 51
         "Bucket"=>$bucket,
52 52
         "Key"=>$keyprefix."EOMeta",
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
         echo "upload".$i."\r\n";
68 68
         $args=array(
69 69
             "Bucket"=>$bucket,
70
-        	"Key"=>$keyprefix."EOMeta",
71
-        	"LastPart"=>($i===$count-1),
70
+            "Key"=>$keyprefix."EOMeta",
71
+            "LastPart"=>($i===$count-1),
72 72
             "Options"=>array(
73 73
                 "partNumber"=>$i+1,
74 74
                 "uploadId"=>$uploadid
@@ -95,42 +95,42 @@  discard block
 block discarded – undo
95 95
     $result = $client->completeMultipartUpload($args);
96 96
 
97 97
     rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOMeta",
98
-    	"D://testdown/down",base64_encode(md5_file("D://IMG.jpg")));
98
+        "D://testdown/down",base64_encode(md5_file("D://IMG.jpg")));
99 99
 }
100 100
 function rangeGetAndCheckMd5($client,$bucket,$key,$file,$expectedMd5){
101
-	$args = array("Bucket"=>$bucket,"Key"=>$key);
102
-	$meta = $client->getObjectMeta($args);
103
-	$contentlength = $meta["ObjectMeta"]["Content-Length"];
101
+    $args = array("Bucket"=>$bucket,"Key"=>$key);
102
+    $meta = $client->getObjectMeta($args);
103
+    $contentlength = $meta["ObjectMeta"]["Content-Length"];
104 104
 
105
-	$filelist = array();
105
+    $filelist = array();
106 106
 
107
-	for($begin = 0;$begin <$contentlength;){
108
-		$index = rand((int)($contentlength/20),(int)($contentlength/10));
109
-		$range = array("start"=>$begin,"end"=>$begin+$index);
110
-		$destFile = $file.$begin."-".($begin+$index);
111
-		array_push($filelist,$destFile);
112
-		$begin += ($index+1);
113
-		$args = array(
114
-			"Bucket"=>$bucket,
115
-			"Key"=>$key,
116
-			"Range"=>$range,
117
-			"WriteTo"=>$destFile
118
-		);
119
-		$client->getObject($args);
120
-	}
107
+    for($begin = 0;$begin <$contentlength;){
108
+        $index = rand((int)($contentlength/20),(int)($contentlength/10));
109
+        $range = array("start"=>$begin,"end"=>$begin+$index);
110
+        $destFile = $file.$begin."-".($begin+$index);
111
+        array_push($filelist,$destFile);
112
+        $begin += ($index+1);
113
+        $args = array(
114
+            "Bucket"=>$bucket,
115
+            "Key"=>$key,
116
+            "Range"=>$range,
117
+            "WriteTo"=>$destFile
118
+        );
119
+        $client->getObject($args);
120
+    }
121 121
 
122
-	foreach ($filelist as $key => $value) {
123
-		$handle = fopen($value,"r");
124
-		$size = filesize($value);
125
-		if($size > 0){
126
-			$content = fread($handle,$size);
127
-			file_put_contents($file,$content,FILE_APPEND);
128
-		}
129
-		fclose($handle);
130
-		@unlink($value);
131
-	}
132
-	$md5 = base64_encode(md5_file($file));
133
-	if($md5 != $expectedMd5)
134
-		throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1);
135
-	@unlink($file);	
122
+    foreach ($filelist as $key => $value) {
123
+        $handle = fopen($value,"r");
124
+        $size = filesize($value);
125
+        if($size > 0){
126
+            $content = fread($handle,$size);
127
+            file_put_contents($file,$content,FILE_APPEND);
128
+        }
129
+        fclose($handle);
130
+        @unlink($value);
131
+    }
132
+    $md5 = base64_encode(md5_file($file));
133
+    if($md5 != $expectedMd5)
134
+        throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1);
135
+    @unlink($file);	
136 136
 }
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-define("ENCRYPTPTION_STORAGE_MODE","ObjectMetadata");
2
+define("ENCRYPTPTION_STORAGE_MODE", "ObjectMetadata");
3 3
 require_once "../Ks3EncryptionClient.class.php";
4 4
 require_once "../Ks3Client.class.php";
5 5
 $bucket = "test-encryption";
@@ -7,16 +7,16 @@  discard block
 block discarded – undo
7 7
 
8 8
 $filename = "secret.key";
9 9
 $handle = fopen($filename, "r");
10
-$contents = fread($handle, filesize ($filename));
10
+$contents = fread($handle, filesize($filename));
11 11
 fclose($handle);
12 12
 
13
-$client = new Ks3EncryptionClient("lMQTr0hNlMpB0iOk/i+x","D4CsYLs75JcWEjbiI22zR3P7kJ/+5B1qdEje7A7I",$contents);
14
-putObjectByContentAndGetObjectUsingMeta($client,$bucket,$keyprefix);
15
-putObjectByFileAndGetObjectUsingMeta($client,$bucket,$keyprefix);
16
-multipartUpload($client,$bucket,$keyprefix);
13
+$client = new Ks3EncryptionClient("lMQTr0hNlMpB0iOk/i+x", "D4CsYLs75JcWEjbiI22zR3P7kJ/+5B1qdEje7A7I", $contents);
14
+putObjectByContentAndGetObjectUsingMeta($client, $bucket, $keyprefix);
15
+putObjectByFileAndGetObjectUsingMeta($client, $bucket, $keyprefix);
16
+multipartUpload($client, $bucket, $keyprefix);
17 17
 
18
-function putObjectByContentAndGetObjectUsingMeta($client,$bucket,$keyprefix){
19
-	for($i = 45 ;$i < 60;$i++){
18
+function putObjectByContentAndGetObjectUsingMeta($client, $bucket, $keyprefix) {
19
+	for ($i = 45; $i < 60; $i++) {
20 20
 
21 21
 		$content = EncryptionUtil::genereateOnceUsedKey($i);
22 22
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 			"Content"=>$content
28 28
 		);
29 29
 		$client->putObjectByContent($args);
30
-		rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOMeta",
31
-			"D://testdown/down",base64_encode(md5($args["Content"])));
30
+		rangeGetAndCheckMd5($client, $bucket, $keyprefix."EOMeta",
31
+			"D://testdown/down", base64_encode(md5($args["Content"])));
32 32
 	}
33 33
 }
34
-function putObjectByFileAndGetObjectUsingMeta($client,$bucket,$keyprefix){
34
+function putObjectByFileAndGetObjectUsingMeta($client, $bucket, $keyprefix) {
35 35
 
36 36
 	$args = array(
37 37
 		"Bucket"=>$bucket,
@@ -42,39 +42,39 @@  discard block
 block discarded – undo
42 42
 			)
43 43
 	);
44 44
 	$client->putObjectByFile($args);
45
-	rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOMeta",
46
-			"D://testdown/down",base64_encode(md5_file("D://IMG.jpg")));
45
+	rangeGetAndCheckMd5($client, $bucket, $keyprefix."EOMeta",
46
+			"D://testdown/down", base64_encode(md5_file("D://IMG.jpg")));
47 47
 }
48
-function multipartUpload($client,$bucket,$keyprefix){
48
+function multipartUpload($client, $bucket, $keyprefix) {
49 49
 	//初始化分开上传,获取uploadid
50 50
     $args = array(
51 51
         "Bucket"=>$bucket,
52 52
         "Key"=>$keyprefix."EOMeta",
53 53
     );
54 54
     $uploadid = $client->initMultipartUpload($args);
55
-    $uploadid = $uploadid["UploadId"];//获取到uploadid
55
+    $uploadid = $uploadid["UploadId"]; //获取到uploadid
56 56
         //开始上传
57 57
 
58
-    $file = "D://IMG.jpg";//要上传的文件
58
+    $file = "D://IMG.jpg"; //要上传的文件
59 59
     $partsize = 1024*100;
60
-    $resource = fopen($file,"r");
60
+    $resource = fopen($file, "r");
61 61
     $stat = fstat($resource);
62
-    $total = $stat["size"];//获取文件的总大小
62
+    $total = $stat["size"]; //获取文件的总大小
63 63
     fclose($resource);
64
-    $count = (int)(($total-1)/$partsize)+1;//计算文件需要分几块上传
65
-    for($i = 0;$i < $count;$i++){
64
+    $count = (int)(($total-1)/$partsize)+1; //计算文件需要分几块上传
65
+    for ($i = 0; $i < $count; $i++) {
66 66
         //依次上传每一块
67 67
         echo "upload".$i."\r\n";
68
-        $args=array(
68
+        $args = array(
69 69
             "Bucket"=>$bucket,
70 70
         	"Key"=>$keyprefix."EOMeta",
71
-        	"LastPart"=>($i===$count-1),
71
+        	"LastPart"=>($i === $count-1),
72 72
             "Options"=>array(
73 73
                 "partNumber"=>$i+1,
74 74
                 "uploadId"=>$uploadid
75 75
             ),
76 76
             "ObjectMeta"=>array(
77
-                "Content-Length"=>min($partsize,$total-$partsize*$i)//每次上传$partsize大小
77
+                "Content-Length"=>min($partsize, $total-$partsize*$i)//每次上传$partsize大小
78 78
             ),
79 79
             "Content"=>array(
80 80
                 "content"=>$file,
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
         $etag = $client->uploadPart($args);
85 85
         $etag = $etag["ETag"];
86 86
     }
87
-    $parts = $client->listParts(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOMeta","Options"=>array("uploadId"=>$uploadid)));
87
+    $parts = $client->listParts(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOMeta", "Options"=>array("uploadId"=>$uploadid)));
88 88
     //结束上传
89
-    $args=array(
89
+    $args = array(
90 90
         "Bucket"=>$bucket,
91 91
         "Key"=>$keyprefix."EOMeta",
92 92
         "Options"=>array("uploadId"=>$uploadid),
@@ -94,21 +94,21 @@  discard block
 block discarded – undo
94 94
     );
95 95
     $result = $client->completeMultipartUpload($args);
96 96
 
97
-    rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOMeta",
98
-    	"D://testdown/down",base64_encode(md5_file("D://IMG.jpg")));
97
+    rangeGetAndCheckMd5($client, $bucket, $keyprefix."EOMeta",
98
+    	"D://testdown/down", base64_encode(md5_file("D://IMG.jpg")));
99 99
 }
100
-function rangeGetAndCheckMd5($client,$bucket,$key,$file,$expectedMd5){
101
-	$args = array("Bucket"=>$bucket,"Key"=>$key);
100
+function rangeGetAndCheckMd5($client, $bucket, $key, $file, $expectedMd5) {
101
+	$args = array("Bucket"=>$bucket, "Key"=>$key);
102 102
 	$meta = $client->getObjectMeta($args);
103 103
 	$contentlength = $meta["ObjectMeta"]["Content-Length"];
104 104
 
105 105
 	$filelist = array();
106 106
 
107
-	for($begin = 0;$begin <$contentlength;){
108
-		$index = rand((int)($contentlength/20),(int)($contentlength/10));
109
-		$range = array("start"=>$begin,"end"=>$begin+$index);
107
+	for ($begin = 0; $begin < $contentlength;) {
108
+		$index = rand((int)($contentlength/20), (int)($contentlength/10));
109
+		$range = array("start"=>$begin, "end"=>$begin+$index);
110 110
 		$destFile = $file.$begin."-".($begin+$index);
111
-		array_push($filelist,$destFile);
111
+		array_push($filelist, $destFile);
112 112
 		$begin += ($index+1);
113 113
 		$args = array(
114 114
 			"Bucket"=>$bucket,
@@ -120,17 +120,17 @@  discard block
 block discarded – undo
120 120
 	}
121 121
 
122 122
 	foreach ($filelist as $key => $value) {
123
-		$handle = fopen($value,"r");
123
+		$handle = fopen($value, "r");
124 124
 		$size = filesize($value);
125
-		if($size > 0){
126
-			$content = fread($handle,$size);
127
-			file_put_contents($file,$content,FILE_APPEND);
125
+		if ($size > 0) {
126
+			$content = fread($handle, $size);
127
+			file_put_contents($file, $content, FILE_APPEND);
128 128
 		}
129 129
 		fclose($handle);
130 130
 		@unlink($value);
131 131
 	}
132 132
 	$md5 = base64_encode(md5_file($file));
133
-	if($md5 != $expectedMd5)
133
+	if ($md5 != $expectedMd5)
134 134
 		throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1);
135 135
 	@unlink($file);	
136 136
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -130,7 +130,8 @@
 block discarded – undo
130 130
 		@unlink($value);
131 131
 	}
132 132
 	$md5 = base64_encode(md5_file($file));
133
-	if($md5 != $expectedMd5)
134
-		throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1);
133
+	if($md5 != $expectedMd5) {
134
+			throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1);
135
+	}
135 136
 	@unlink($file);	
136 137
 }
Please login to merge, or discard this patch.
src/service/ksyun/bin/samples/TestEncryptionClientFile.php 3 patches
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -17,33 +17,33 @@  discard block
 block discarded – undo
17 17
 copyAnddeleteObject($client,$bucket,$keyprefix);
18 18
 
19 19
 function putObjectByContentAndGetObjectUsingInstruction($client,$bucket,$keyprefix){
20
-	$content = EncryptionUtil::genereateOnceUsedKey(rand(100,1000));
21
-	$args = array(
22
-		"Bucket"=>$bucket,
23
-		"Key"=>$keyprefix."EOFile",
24
-		"ACL"=>"public-read",
25
-		"Content"=>$content
26
-	);
27
-	$client->putObjectByContent($args);
28
-	rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOFile",
29
-			"D://testdown/down",base64_encode(md5($args["Content"])));
20
+    $content = EncryptionUtil::genereateOnceUsedKey(rand(100,1000));
21
+    $args = array(
22
+        "Bucket"=>$bucket,
23
+        "Key"=>$keyprefix."EOFile",
24
+        "ACL"=>"public-read",
25
+        "Content"=>$content
26
+    );
27
+    $client->putObjectByContent($args);
28
+    rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOFile",
29
+            "D://testdown/down",base64_encode(md5($args["Content"])));
30 30
 }
31 31
 function putObjectByFileAndGetObjectUsingFile($client,$bucket,$keyprefix){
32 32
 
33
-	$args = array(
34
-		"Bucket"=>$bucket,
35
-		"Key"=>$keyprefix."EOFile",
36
-		"ACL"=>"public-read",
37
-		"Content"=>array(
38
-			"content"=>"D://IMG.jpg"
39
-			)
40
-	);
41
-	$client->putObjectByFile($args);
42
-	rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOFile",
43
-			"D://testdown/down",base64_encode(md5_file("D://IMG.jpg")));
33
+    $args = array(
34
+        "Bucket"=>$bucket,
35
+        "Key"=>$keyprefix."EOFile",
36
+        "ACL"=>"public-read",
37
+        "Content"=>array(
38
+            "content"=>"D://IMG.jpg"
39
+            )
40
+    );
41
+    $client->putObjectByFile($args);
42
+    rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOFile",
43
+            "D://testdown/down",base64_encode(md5_file("D://IMG.jpg")));
44 44
 }
45 45
 function multipartUpload($client,$bucket,$keyprefix){
46
-	//初始化分开上传,获取uploadid
46
+    //初始化分开上传,获取uploadid
47 47
     $args = array(
48 48
         "Bucket"=>$bucket,
49 49
         "Key"=>$keyprefix."EOFile",
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
         echo "upload".$i."\r\n";
65 65
         $args=array(
66 66
             "Bucket"=>$bucket,
67
-        	"Key"=>$keyprefix."EOFile",
68
-        	"LastPart"=>($i===$count-1),
67
+            "Key"=>$keyprefix."EOFile",
68
+            "LastPart"=>($i===$count-1),
69 69
             "Options"=>array(
70 70
                 "partNumber"=>$i+1,
71 71
                 "uploadId"=>$uploadid
@@ -92,79 +92,79 @@  discard block
 block discarded – undo
92 92
     $result = $client->completeMultipartUpload($args);
93 93
 
94 94
     rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOFile",
95
-    	"D://testdown/down",base64_encode(md5_file("D://IMG.jpg")));
95
+        "D://testdown/down",base64_encode(md5_file("D://IMG.jpg")));
96 96
 }
97 97
 function copyAnddeleteObject($client,$bucket,$keyprefix){
98
-	$content = EncryptionUtil::genereateOnceUsedKey(rand(100,1000));
99
-	$args = array(
100
-		"Bucket"=>$bucket,
101
-		"Key"=>$keyprefix."EOFile",
102
-		"ACL"=>"public-read",
103
-		"Content"=>$content
104
-	);
105
-	$client->putObjectByContent($args);
98
+    $content = EncryptionUtil::genereateOnceUsedKey(rand(100,1000));
99
+    $args = array(
100
+        "Bucket"=>$bucket,
101
+        "Key"=>$keyprefix."EOFile",
102
+        "ACL"=>"public-read",
103
+        "Content"=>$content
104
+    );
105
+    $client->putObjectByContent($args);
106 106
 
107
-	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")))
108
-		$client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"));
109
-	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")))
110
-		$client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"));
107
+    if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")))
108
+        $client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"));
109
+    if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")))
110
+        $client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"));
111 111
 
112
-	$copyReq = array(
113
-		"Bucket"=>$bucket,
114
-		"Key"=>$keyprefix."EOFileCopy",
115
-		"CopySource"=>array(
116
-			"Bucket"=>$bucket,
117
-			"Key"=>$keyprefix."EOFile"
118
-			)
119
-		);
120
-	$client->copyObject($copyReq);
112
+    $copyReq = array(
113
+        "Bucket"=>$bucket,
114
+        "Key"=>$keyprefix."EOFileCopy",
115
+        "CopySource"=>array(
116
+            "Bucket"=>$bucket,
117
+            "Key"=>$keyprefix."EOFile"
118
+            )
119
+        );
120
+    $client->copyObject($copyReq);
121 121
 
122
-	if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")))
123
-		throw new Exception("not found ".$keyprefix."EOFileCopy");
124
-	if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")))
125
-		throw new Exception("not found ".$keyprefix."EOFileCopy.instruction");
122
+    if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")))
123
+        throw new Exception("not found ".$keyprefix."EOFileCopy");
124
+    if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")))
125
+        throw new Exception("not found ".$keyprefix."EOFileCopy.instruction");
126 126
 
127
-	$client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"));
127
+    $client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"));
128 128
 
129
-	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")))
130
-		throw new Exception("found ".$keyprefix."EOFileCopy");
131
-	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")))
132
-		throw new Exception("found ".$keyprefix."EOFileCopy.instruction");
129
+    if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")))
130
+        throw new Exception("found ".$keyprefix."EOFileCopy");
131
+    if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")))
132
+        throw new Exception("found ".$keyprefix."EOFileCopy.instruction");
133 133
 }
134 134
 function rangeGetAndCheckMd5($client,$bucket,$key,$file,$expectedMd5){
135
-	$args = array("Bucket"=>$bucket,"Key"=>$key);
136
-	$meta = $client->getObjectMeta($args);
137
-	$contentlength = $meta["ObjectMeta"]["Content-Length"];
135
+    $args = array("Bucket"=>$bucket,"Key"=>$key);
136
+    $meta = $client->getObjectMeta($args);
137
+    $contentlength = $meta["ObjectMeta"]["Content-Length"];
138 138
 
139
-	$filelist = array();
139
+    $filelist = array();
140 140
 
141
-	for($begin = 0;$begin <$contentlength;){
142
-		$index = rand((int)($contentlength/20),(int)($contentlength/10));
143
-		$range = array("start"=>$begin,"end"=>$begin+$index);
144
-		$destFile = $file.$begin."-".($begin+$index);
145
-		array_push($filelist,$destFile);
146
-		$begin += ($index+1);
147
-		$args = array(
148
-			"Bucket"=>$bucket,
149
-			"Key"=>$key,
150
-			"Range"=>$range,
151
-			"WriteTo"=>$destFile
152
-		);
153
-		$client->getObject($args);
154
-	}
141
+    for($begin = 0;$begin <$contentlength;){
142
+        $index = rand((int)($contentlength/20),(int)($contentlength/10));
143
+        $range = array("start"=>$begin,"end"=>$begin+$index);
144
+        $destFile = $file.$begin."-".($begin+$index);
145
+        array_push($filelist,$destFile);
146
+        $begin += ($index+1);
147
+        $args = array(
148
+            "Bucket"=>$bucket,
149
+            "Key"=>$key,
150
+            "Range"=>$range,
151
+            "WriteTo"=>$destFile
152
+        );
153
+        $client->getObject($args);
154
+    }
155 155
 
156
-	foreach ($filelist as $key => $value) {
157
-		$handle = fopen($value,"r");
158
-		$size = filesize($value);
159
-		if($size > 0){
160
-			$content = fread($handle,$size);
161
-			file_put_contents($file,$content,FILE_APPEND);
162
-		}
163
-		fclose($handle);
164
-		@unlink($value);
165
-	}
166
-	$md5 = base64_encode(md5_file($file));
167
-	if($md5 != $expectedMd5)
168
-		throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1);
169
-	@unlink($file);	
156
+    foreach ($filelist as $key => $value) {
157
+        $handle = fopen($value,"r");
158
+        $size = filesize($value);
159
+        if($size > 0){
160
+            $content = fread($handle,$size);
161
+            file_put_contents($file,$content,FILE_APPEND);
162
+        }
163
+        fclose($handle);
164
+        @unlink($value);
165
+    }
166
+    $md5 = base64_encode(md5_file($file));
167
+    if($md5 != $expectedMd5)
168
+        throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1);
169
+    @unlink($file);	
170 170
 }
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-define("ENCRYPTPTION_STORAGE_MODE","InstructionFile");
2
+define("ENCRYPTPTION_STORAGE_MODE", "InstructionFile");
3 3
 require_once "../Ks3EncryptionClient.class.php";
4 4
 require_once "../Ks3Client.class.php";
5 5
 $bucket = "test-encryption";
@@ -7,17 +7,17 @@  discard block
 block discarded – undo
7 7
 
8 8
 $filename = "secret.key";
9 9
 $handle = fopen($filename, "r");
10
-$contents = fread($handle, filesize ($filename));
10
+$contents = fread($handle, filesize($filename));
11 11
 fclose($handle);
12 12
 
13
-$client = new Ks3EncryptionClient("lMQTr0hNlMpB0iOk/i+x","D4CsYLs75JcWEjbiI22zR3P7kJ/+5B1qdEje7A7I",$contents);
14
-putObjectByContentAndGetObjectUsingInstruction($client,$bucket,$keyprefix);
15
-putObjectByFileAndGetObjectUsingFile($client,$bucket,$keyprefix);
16
-multipartUpload($client,$bucket,$keyprefix);
17
-copyAnddeleteObject($client,$bucket,$keyprefix);
13
+$client = new Ks3EncryptionClient("lMQTr0hNlMpB0iOk/i+x", "D4CsYLs75JcWEjbiI22zR3P7kJ/+5B1qdEje7A7I", $contents);
14
+putObjectByContentAndGetObjectUsingInstruction($client, $bucket, $keyprefix);
15
+putObjectByFileAndGetObjectUsingFile($client, $bucket, $keyprefix);
16
+multipartUpload($client, $bucket, $keyprefix);
17
+copyAnddeleteObject($client, $bucket, $keyprefix);
18 18
 
19
-function putObjectByContentAndGetObjectUsingInstruction($client,$bucket,$keyprefix){
20
-	$content = EncryptionUtil::genereateOnceUsedKey(rand(100,1000));
19
+function putObjectByContentAndGetObjectUsingInstruction($client, $bucket, $keyprefix) {
20
+	$content = EncryptionUtil::genereateOnceUsedKey(rand(100, 1000));
21 21
 	$args = array(
22 22
 		"Bucket"=>$bucket,
23 23
 		"Key"=>$keyprefix."EOFile",
@@ -25,10 +25,10 @@  discard block
 block discarded – undo
25 25
 		"Content"=>$content
26 26
 	);
27 27
 	$client->putObjectByContent($args);
28
-	rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOFile",
29
-			"D://testdown/down",base64_encode(md5($args["Content"])));
28
+	rangeGetAndCheckMd5($client, $bucket, $keyprefix."EOFile",
29
+			"D://testdown/down", base64_encode(md5($args["Content"])));
30 30
 }
31
-function putObjectByFileAndGetObjectUsingFile($client,$bucket,$keyprefix){
31
+function putObjectByFileAndGetObjectUsingFile($client, $bucket, $keyprefix) {
32 32
 
33 33
 	$args = array(
34 34
 		"Bucket"=>$bucket,
@@ -39,39 +39,39 @@  discard block
 block discarded – undo
39 39
 			)
40 40
 	);
41 41
 	$client->putObjectByFile($args);
42
-	rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOFile",
43
-			"D://testdown/down",base64_encode(md5_file("D://IMG.jpg")));
42
+	rangeGetAndCheckMd5($client, $bucket, $keyprefix."EOFile",
43
+			"D://testdown/down", base64_encode(md5_file("D://IMG.jpg")));
44 44
 }
45
-function multipartUpload($client,$bucket,$keyprefix){
45
+function multipartUpload($client, $bucket, $keyprefix) {
46 46
 	//初始化分开上传,获取uploadid
47 47
     $args = array(
48 48
         "Bucket"=>$bucket,
49 49
         "Key"=>$keyprefix."EOFile",
50 50
     );
51 51
     $uploadid = $client->initMultipartUpload($args);
52
-    $uploadid = $uploadid["UploadId"];//获取到uploadid
52
+    $uploadid = $uploadid["UploadId"]; //获取到uploadid
53 53
         //开始上传
54 54
 
55
-    $file = "D://IMG.jpg";//要上传的文件
55
+    $file = "D://IMG.jpg"; //要上传的文件
56 56
     $partsize = 1024*100;
57
-    $resource = fopen($file,"r");
57
+    $resource = fopen($file, "r");
58 58
     $stat = fstat($resource);
59
-    $total = $stat["size"];//获取文件的总大小
59
+    $total = $stat["size"]; //获取文件的总大小
60 60
     fclose($resource);
61
-    $count = (int)(($total-1)/$partsize)+1;//计算文件需要分几块上传
62
-    for($i = 0;$i < $count;$i++){
61
+    $count = (int)(($total-1)/$partsize)+1; //计算文件需要分几块上传
62
+    for ($i = 0; $i < $count; $i++) {
63 63
         //依次上传每一块
64 64
         echo "upload".$i."\r\n";
65
-        $args=array(
65
+        $args = array(
66 66
             "Bucket"=>$bucket,
67 67
         	"Key"=>$keyprefix."EOFile",
68
-        	"LastPart"=>($i===$count-1),
68
+        	"LastPart"=>($i === $count-1),
69 69
             "Options"=>array(
70 70
                 "partNumber"=>$i+1,
71 71
                 "uploadId"=>$uploadid
72 72
             ),
73 73
             "ObjectMeta"=>array(
74
-                "Content-Length"=>min($partsize,$total-$partsize*$i)//每次上传$partsize大小
74
+                "Content-Length"=>min($partsize, $total-$partsize*$i)//每次上传$partsize大小
75 75
             ),
76 76
             "Content"=>array(
77 77
                 "content"=>$file,
@@ -81,9 +81,9 @@  discard block
 block discarded – undo
81 81
         $etag = $client->uploadPart($args);
82 82
         $etag = $etag["ETag"];
83 83
     }
84
-    $parts = $client->listParts(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFile","Options"=>array("uploadId"=>$uploadid)));
84
+    $parts = $client->listParts(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFile", "Options"=>array("uploadId"=>$uploadid)));
85 85
     //结束上传
86
-    $args=array(
86
+    $args = array(
87 87
         "Bucket"=>$bucket,
88 88
         "Key"=>$keyprefix."EOFile",
89 89
         "Options"=>array("uploadId"=>$uploadid),
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
     );
92 92
     $result = $client->completeMultipartUpload($args);
93 93
 
94
-    rangeGetAndCheckMd5($client,$bucket,$keyprefix."EOFile",
95
-    	"D://testdown/down",base64_encode(md5_file("D://IMG.jpg")));
94
+    rangeGetAndCheckMd5($client, $bucket, $keyprefix."EOFile",
95
+    	"D://testdown/down", base64_encode(md5_file("D://IMG.jpg")));
96 96
 }
97
-function copyAnddeleteObject($client,$bucket,$keyprefix){
98
-	$content = EncryptionUtil::genereateOnceUsedKey(rand(100,1000));
97
+function copyAnddeleteObject($client, $bucket, $keyprefix) {
98
+	$content = EncryptionUtil::genereateOnceUsedKey(rand(100, 1000));
99 99
 	$args = array(
100 100
 		"Bucket"=>$bucket,
101 101
 		"Key"=>$keyprefix."EOFile",
@@ -104,10 +104,10 @@  discard block
 block discarded – undo
104 104
 	);
105 105
 	$client->putObjectByContent($args);
106 106
 
107
-	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")))
108
-		$client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"));
109
-	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")))
110
-		$client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"));
107
+	if ($client->objectExists(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy")))
108
+		$client->deleteObject(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy"));
109
+	if ($client->objectExists(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy.instruction")))
110
+		$client->deleteObject(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy.instruction"));
111 111
 
112 112
 	$copyReq = array(
113 113
 		"Bucket"=>$bucket,
@@ -119,30 +119,30 @@  discard block
 block discarded – undo
119 119
 		);
120 120
 	$client->copyObject($copyReq);
121 121
 
122
-	if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")))
122
+	if (!$client->objectExists(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy")))
123 123
 		throw new Exception("not found ".$keyprefix."EOFileCopy");
124
-	if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")))
124
+	if (!$client->objectExists(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy.instruction")))
125 125
 		throw new Exception("not found ".$keyprefix."EOFileCopy.instruction");
126 126
 
127
-	$client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"));
127
+	$client->deleteObject(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy"));
128 128
 
129
-	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")))
129
+	if ($client->objectExists(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy")))
130 130
 		throw new Exception("found ".$keyprefix."EOFileCopy");
131
-	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")))
131
+	if ($client->objectExists(array("Bucket"=>$bucket, "Key"=>$keyprefix."EOFileCopy.instruction")))
132 132
 		throw new Exception("found ".$keyprefix."EOFileCopy.instruction");
133 133
 }
134
-function rangeGetAndCheckMd5($client,$bucket,$key,$file,$expectedMd5){
135
-	$args = array("Bucket"=>$bucket,"Key"=>$key);
134
+function rangeGetAndCheckMd5($client, $bucket, $key, $file, $expectedMd5) {
135
+	$args = array("Bucket"=>$bucket, "Key"=>$key);
136 136
 	$meta = $client->getObjectMeta($args);
137 137
 	$contentlength = $meta["ObjectMeta"]["Content-Length"];
138 138
 
139 139
 	$filelist = array();
140 140
 
141
-	for($begin = 0;$begin <$contentlength;){
142
-		$index = rand((int)($contentlength/20),(int)($contentlength/10));
143
-		$range = array("start"=>$begin,"end"=>$begin+$index);
141
+	for ($begin = 0; $begin < $contentlength;) {
142
+		$index = rand((int)($contentlength/20), (int)($contentlength/10));
143
+		$range = array("start"=>$begin, "end"=>$begin+$index);
144 144
 		$destFile = $file.$begin."-".($begin+$index);
145
-		array_push($filelist,$destFile);
145
+		array_push($filelist, $destFile);
146 146
 		$begin += ($index+1);
147 147
 		$args = array(
148 148
 			"Bucket"=>$bucket,
@@ -154,17 +154,17 @@  discard block
 block discarded – undo
154 154
 	}
155 155
 
156 156
 	foreach ($filelist as $key => $value) {
157
-		$handle = fopen($value,"r");
157
+		$handle = fopen($value, "r");
158 158
 		$size = filesize($value);
159
-		if($size > 0){
160
-			$content = fread($handle,$size);
161
-			file_put_contents($file,$content,FILE_APPEND);
159
+		if ($size > 0) {
160
+			$content = fread($handle, $size);
161
+			file_put_contents($file, $content, FILE_APPEND);
162 162
 		}
163 163
 		fclose($handle);
164 164
 		@unlink($value);
165 165
 	}
166 166
 	$md5 = base64_encode(md5_file($file));
167
-	if($md5 != $expectedMd5)
167
+	if ($md5 != $expectedMd5)
168 168
 		throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1);
169 169
 	@unlink($file);	
170 170
 }
Please login to merge, or discard this patch.
Braces   +22 added lines, -15 removed lines patch added patch discarded remove patch
@@ -104,10 +104,12 @@  discard block
 block discarded – undo
104 104
 	);
105 105
 	$client->putObjectByContent($args);
106 106
 
107
-	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")))
108
-		$client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"));
109
-	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")))
110
-		$client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"));
107
+	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"))) {
108
+			$client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"));
109
+	}
110
+	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"))) {
111
+			$client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"));
112
+	}
111 113
 
112 114
 	$copyReq = array(
113 115
 		"Bucket"=>$bucket,
@@ -119,18 +121,22 @@  discard block
 block discarded – undo
119 121
 		);
120 122
 	$client->copyObject($copyReq);
121 123
 
122
-	if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")))
123
-		throw new Exception("not found ".$keyprefix."EOFileCopy");
124
-	if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")))
125
-		throw new Exception("not found ".$keyprefix."EOFileCopy.instruction");
124
+	if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"))) {
125
+			throw new Exception("not found ".$keyprefix."EOFileCopy");
126
+	}
127
+	if(!$client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"))) {
128
+			throw new Exception("not found ".$keyprefix."EOFileCopy.instruction");
129
+	}
126 130
 
127 131
 	$client->deleteObject(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"));
128 132
 
129
-	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy")))
130
-		throw new Exception("found ".$keyprefix."EOFileCopy");
131
-	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction")))
132
-		throw new Exception("found ".$keyprefix."EOFileCopy.instruction");
133
-}
133
+	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy"))) {
134
+			throw new Exception("found ".$keyprefix."EOFileCopy");
135
+	}
136
+	if($client->objectExists(array("Bucket"=>$bucket,"Key"=>$keyprefix."EOFileCopy.instruction"))) {
137
+			throw new Exception("found ".$keyprefix."EOFileCopy.instruction");
138
+	}
139
+	}
134 140
 function rangeGetAndCheckMd5($client,$bucket,$key,$file,$expectedMd5){
135 141
 	$args = array("Bucket"=>$bucket,"Key"=>$key);
136 142
 	$meta = $client->getObjectMeta($args);
@@ -164,7 +170,8 @@  discard block
 block discarded – undo
164 170
 		@unlink($value);
165 171
 	}
166 172
 	$md5 = base64_encode(md5_file($file));
167
-	if($md5 != $expectedMd5)
168
-		throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1);
173
+	if($md5 != $expectedMd5) {
174
+			throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1);
175
+	}
169 176
 	@unlink($file);	
170 177
 }
Please login to merge, or discard this patch.
src/service/ksyun/bin/samples/Samples.php 2 patches
Indentation   +316 added lines, -316 removed lines patch added patch discarded remove patch
@@ -33,381 +33,381 @@
 block discarded – undo
33 33
 //print_r(putAdp($client));
34 34
 //print_r(postObject($client));
35 35
 function listBuckets($client){
36
-	return $client->listBuckets();
36
+    return $client->listBuckets();
37 37
 }
38 38
 function deleteBucket($client){
39
-	return $client->deleteBucket(array("Bucket"=>"ksc-scm"));
39
+    return $client->deleteBucket(array("Bucket"=>"ksc-scm"));
40 40
 }
41 41
 function deleteBucketCORS($client){
42
-	return $client->deleteBucketCORS(array("Bucket"=>"ksc-scm"));
42
+    return $client->deleteBucketCORS(array("Bucket"=>"ksc-scm"));
43 43
 }
44 44
 function listObjects($client){
45
-	$args = array(
46
-		"Bucket"=>"lijunwei.test",
47
-		"Options"=>array(
48
-			//"prefix"=>"dir/",
49
-			"max-keys"=>4,
50
-			//"marker"=>"123.pdf",
51
-			"delimiter"=>"/"
52
-			)
53
-		);
54
-	return $client->listObjects($args);
45
+    $args = array(
46
+        "Bucket"=>"lijunwei.test",
47
+        "Options"=>array(
48
+            //"prefix"=>"dir/",
49
+            "max-keys"=>4,
50
+            //"marker"=>"123.pdf",
51
+            "delimiter"=>"/"
52
+            )
53
+        );
54
+    return $client->listObjects($args);
55 55
 }
56 56
 function getBucketAcl($client){
57
-	return $client->getBucketAcl(array("Bucket"=>"aaphp"));
57
+    return $client->getBucketAcl(array("Bucket"=>"aaphp"));
58 58
 }
59 59
 function getBucketCORS($client){
60
-	return $client->getBucketCORS(array("Bucket"=>"ksc-scm"));
60
+    return $client->getBucketCORS(array("Bucket"=>"ksc-scm"));
61 61
 }
62 62
 function getBucketLocation($client){
63
-	return $client->getBucketLocation(array("Bucket"=>"ksc-scm"));
63
+    return $client->getBucketLocation(array("Bucket"=>"ksc-scm"));
64 64
 }
65 65
 function getBucketLogging($client){
66
-	return $client->getBucketLogging(array("Bucket"=>"ksc-scm"));
66
+    return $client->getBucketLogging(array("Bucket"=>"ksc-scm"));
67 67
 }
68 68
 function bucketExists($client){
69
-	$args = array("Bucket"=>"ksc-scm");
70
-	return $client->bucketExists($args);
69
+    $args = array("Bucket"=>"ksc-scm");
70
+    return $client->bucketExists($args);
71 71
 }
72 72
 function createBucket($client){
73
-	$args = array(
74
-		"Bucket"=>"ksc-scm",
75
-		"ACL"=>"private"
76
-		);
77
-	return $client->createBucket($args);
73
+    $args = array(
74
+        "Bucket"=>"ksc-scm",
75
+        "ACL"=>"private"
76
+        );
77
+    return $client->createBucket($args);
78 78
 }
79 79
 function setBucketAcl($client){
80
-	$args = array(
81
-		"Bucket"=>"ksc-scm",
82
-		"ACL"=>"private"
83
-		);
84
-	return $client->setBucketAcl($args);
80
+    $args = array(
81
+        "Bucket"=>"ksc-scm",
82
+        "ACL"=>"private"
83
+        );
84
+    return $client->setBucketAcl($args);
85 85
 }
86 86
 function setBucketCORS($client){
87
-	$args = array(
88
-		"Bucket"=>"ksc-scm",
89
-		"CORS"=>array(
90
-			array(
91
-				"AllowedMethod"=>array("GET","PUT"),
92
-				"AllowedOrigin"=>array("http://www.kingsoft.com"),
93
-				"AllowedHeader"=>array("*"),
94
-				"ExposeHeader"=>array("*"),
95
-				"MaxAgeSeconds"=>10
96
-			),
97
-			array(
98
-				"AllowedMethod"=>array("GET","PUT"),
99
-				"AllowedOrigin"=>array("*"),
100
-				"AllowedHeader"=>array("*"),
101
-				"ExposeHeader"=>array("*"),
102
-				"MaxAgeSeconds"=>10
103
-			)
104
-		)
105
-	);
106
-	return $client->setBucketCORS($args);
87
+    $args = array(
88
+        "Bucket"=>"ksc-scm",
89
+        "CORS"=>array(
90
+            array(
91
+                "AllowedMethod"=>array("GET","PUT"),
92
+                "AllowedOrigin"=>array("http://www.kingsoft.com"),
93
+                "AllowedHeader"=>array("*"),
94
+                "ExposeHeader"=>array("*"),
95
+                "MaxAgeSeconds"=>10
96
+            ),
97
+            array(
98
+                "AllowedMethod"=>array("GET","PUT"),
99
+                "AllowedOrigin"=>array("*"),
100
+                "AllowedHeader"=>array("*"),
101
+                "ExposeHeader"=>array("*"),
102
+                "MaxAgeSeconds"=>10
103
+            )
104
+        )
105
+    );
106
+    return $client->setBucketCORS($args);
107 107
 }
108 108
 function setBucketLogging($client){
109
-	$args = array(
110
-		"Bucket"=>"ksc-scm",
111
-		"BucketLogging"=>array(
112
-			"Enable"=>TRUE,
113
-			"TargetBucket"=>"ksc-scm",
114
-			"TargetPrefix"=>"X-KSS"
115
-			)
116
-		);
117
-	return $client->setBucketLogging($args);
109
+    $args = array(
110
+        "Bucket"=>"ksc-scm",
111
+        "BucketLogging"=>array(
112
+            "Enable"=>TRUE,
113
+            "TargetBucket"=>"ksc-scm",
114
+            "TargetPrefix"=>"X-KSS"
115
+            )
116
+        );
117
+    return $client->setBucketLogging($args);
118 118
 }
119 119
 function deleteObject($client){
120
-	$args = array(
121
-		"Bucket"=>"ksc-scm",
122
-		"Key"=>"123.pdf"
123
-		);
124
-	return $client->deleteObject($args);
120
+    $args = array(
121
+        "Bucket"=>"ksc-scm",
122
+        "Key"=>"123.pdf"
123
+        );
124
+    return $client->deleteObject($args);
125 125
 }
126 126
 function deleteObjects($client){
127
-	$args = array(
128
-		"Bucket"=>"ksc-scm",
129
-		"DeleteKeys"=>array("copy/test.zip","copy/123.doc")
130
-		);
131
-	return $client->deleteObjects($args);
127
+    $args = array(
128
+        "Bucket"=>"ksc-scm",
129
+        "DeleteKeys"=>array("copy/test.zip","copy/123.doc")
130
+        );
131
+    return $client->deleteObjects($args);
132 132
 }
133 133
 function getObject($client){
134
-	$args = array(
135
-		"Bucket"=>"aaphp",
136
-		"Key"=>"multi.exe",
137
-		"Range"=>array(
138
-			"start"=>NULL,
139
-			"end"=>4,
140
-			),
141
-		"WriteTo"=>"D://test.zip"
142
-		);
143
-	return $client->getObject($args);
134
+    $args = array(
135
+        "Bucket"=>"aaphp",
136
+        "Key"=>"multi.exe",
137
+        "Range"=>array(
138
+            "start"=>NULL,
139
+            "end"=>4,
140
+            ),
141
+        "WriteTo"=>"D://test.zip"
142
+        );
143
+    return $client->getObject($args);
144 144
 }
145 145
 function getObjectAcl($client){
146
-	$args = array(
147
-		"Bucket"=>"aaphp",
148
-		"Key"=>"multi.exe"
149
-		);
150
-	return $client->getObjectAcl($args);
146
+    $args = array(
147
+        "Bucket"=>"aaphp",
148
+        "Key"=>"multi.exe"
149
+        );
150
+    return $client->getObjectAcl($args);
151 151
 }
152 152
 function objectExists($client){
153
-	$args = array(
154
-		"Bucket"=>"ksc-scm",
155
-		"Key"=>"123.pdf"
156
-		);
157
-	return $client->objectExists($args);
153
+    $args = array(
154
+        "Bucket"=>"ksc-scm",
155
+        "Key"=>"123.pdf"
156
+        );
157
+    return $client->objectExists($args);
158 158
 }
159 159
 function getObjectMeta($client){
160
-	$args = array(
161
-		"Bucket"=>"aaphp",
162
-		"Key"=>"test.zip"
163
-		);
164
-	return $client->getObjectMeta($args);
160
+    $args = array(
161
+        "Bucket"=>"aaphp",
162
+        "Key"=>"test.zip"
163
+        );
164
+    return $client->getObjectMeta($args);
165 165
 }
166 166
 function setObjectAcl($client){
167
-	$args = array(
168
-		"Bucket"=>"aaphp",
169
-		"Key"=>"test.zip",
170
-		"ACL"=>"private"
171
-		);
172
-	return $client->setObjectAcl($args);
167
+    $args = array(
168
+        "Bucket"=>"aaphp",
169
+        "Key"=>"test.zip",
170
+        "ACL"=>"private"
171
+        );
172
+    return $client->setObjectAcl($args);
173 173
 }
174 174
 function copyObject($client){
175
-	$args = array(
176
-		"Bucket"=>"aaphp",
177
-		"Key"=>"copy/test.zip",
178
-		"CopySource"=>array(
179
-			"Bucket"=>"aaphp",
180
-			"Key"=>"test.zip"
181
-			)
182
-		);
183
-	return $client->copyObject($args);
175
+    $args = array(
176
+        "Bucket"=>"aaphp",
177
+        "Key"=>"copy/test.zip",
178
+        "CopySource"=>array(
179
+            "Bucket"=>"aaphp",
180
+            "Key"=>"test.zip"
181
+            )
182
+        );
183
+    return $client->copyObject($args);
184 184
 }
185 185
 function putObjectByFile($client){
186
-	$file = "D://phpput";
187
-	if(Utils::chk_chinese($file)){
188
-		$file = iconv('utf-8','gbk',$file);
189
-	}
190
-	$content = $file;
191
-	$args = array(
192
-		"Bucket"=>"aaphp",
193
-		"Key"=>"stream_upload1.txt",
194
-		"ACL"=>"public-read",
195
-		"ObjectMeta"=>array(
196
-			"Content-Type"=>"image/jpg",//只传0-10字节,
197
-			),
198
-		"Content"=>array(
199
-			"content"=>$file,
200
-			"seek_position"=>0
201
-			),
202
-	);
203
-	return $client->putObjectByFile($args);
186
+    $file = "D://phpput";
187
+    if(Utils::chk_chinese($file)){
188
+        $file = iconv('utf-8','gbk',$file);
189
+    }
190
+    $content = $file;
191
+    $args = array(
192
+        "Bucket"=>"aaphp",
193
+        "Key"=>"stream_upload1.txt",
194
+        "ACL"=>"public-read",
195
+        "ObjectMeta"=>array(
196
+            "Content-Type"=>"image/jpg",//只传0-10字节,
197
+            ),
198
+        "Content"=>array(
199
+            "content"=>$file,
200
+            "seek_position"=>0
201
+            ),
202
+    );
203
+    return $client->putObjectByFile($args);
204 204
 }
205 205
 function multipartUpload($client){
206
-	$args = array(
207
-		"Bucket"=>"aaphp",
208
-		"Key"=>"multi.zip",
209
-		"UserMeta"=>array(
210
-			"x-kss-meta-test"=>"example"
211
-			),
212
-		"ObjectMeta"=>array(
213
-			"Content-Type"=>"text/plain"
214
-			)
215
-		);
216
-	$uploadid = $client->initMultipartUpload($args);
217
-	print_r($uploadid);
218
-	$uploadid = $uploadid["UploadId"];
219
-	echo $uploadid."\r\n";
220
-	//开始上传
206
+    $args = array(
207
+        "Bucket"=>"aaphp",
208
+        "Key"=>"multi.zip",
209
+        "UserMeta"=>array(
210
+            "x-kss-meta-test"=>"example"
211
+            ),
212
+        "ObjectMeta"=>array(
213
+            "Content-Type"=>"text/plain"
214
+            )
215
+        );
216
+    $uploadid = $client->initMultipartUpload($args);
217
+    print_r($uploadid);
218
+    $uploadid = $uploadid["UploadId"];
219
+    echo $uploadid."\r\n";
220
+    //开始上传
221 221
 
222
-	$file = "D://新建文件夹.rar";
223
-	if(Utils::chk_chinese($file)){
224
-		$file = iconv('utf-8','gbk',$file);
225
-	}
226
-	$total = Utils::getFileSize($file);
227
-	$partsize = 1024*1024*5;
228
-	$count = (int)(($total-1)/$partsize)+1;
229
-	echo $count."\r\n";
230
-	for($i = 0;$i < $count;$i++){
231
-		echo "upload".$i."\r\n";
232
-		$args=array(
233
-			"Bucket"=>"aaphp",
234
-			"Key"=>"multi.zip",
235
-			"Options"=>array(
236
-				"partNumber"=>$i+1,
237
-				"uploadId"=>$uploadid
238
-				),
239
-			"ObjectMeta"=>array(
240
-				"Content-Length"=>$partsize
241
-				),
242
-			"Content"=>array(
243
-				"content"=>$file,
244
-				"seek_position"=>$partsize*$i
245
-				)
246
-			);
247
-		$etag = $client->uploadPart($args);
248
-		print_r($etag);
249
-		$etag = $etag["ETag"];
250
-	}
251
-	$parts = $client->listParts(array("Bucket"=>"aaphp","Key"=>"multi.zip","Options"=>array("uploadId"=>$uploadid)));
252
-	print_r($parts);
253
-	//结束上传
254
-	$args=array(
255
-		"Bucket"=>"aaphp",
256
-		"Key"=>"multi.zip",
257
-		"Options"=>array("uploadId"=>$uploadid),
258
-		"Parts"=>$parts["Parts"]
259
-		);
260
-	$result = $client->completeMultipartUpload($args);
261
-	print_r($result);
222
+    $file = "D://新建文件夹.rar";
223
+    if(Utils::chk_chinese($file)){
224
+        $file = iconv('utf-8','gbk',$file);
225
+    }
226
+    $total = Utils::getFileSize($file);
227
+    $partsize = 1024*1024*5;
228
+    $count = (int)(($total-1)/$partsize)+1;
229
+    echo $count."\r\n";
230
+    for($i = 0;$i < $count;$i++){
231
+        echo "upload".$i."\r\n";
232
+        $args=array(
233
+            "Bucket"=>"aaphp",
234
+            "Key"=>"multi.zip",
235
+            "Options"=>array(
236
+                "partNumber"=>$i+1,
237
+                "uploadId"=>$uploadid
238
+                ),
239
+            "ObjectMeta"=>array(
240
+                "Content-Length"=>$partsize
241
+                ),
242
+            "Content"=>array(
243
+                "content"=>$file,
244
+                "seek_position"=>$partsize*$i
245
+                )
246
+            );
247
+        $etag = $client->uploadPart($args);
248
+        print_r($etag);
249
+        $etag = $etag["ETag"];
250
+    }
251
+    $parts = $client->listParts(array("Bucket"=>"aaphp","Key"=>"multi.zip","Options"=>array("uploadId"=>$uploadid)));
252
+    print_r($parts);
253
+    //结束上传
254
+    $args=array(
255
+        "Bucket"=>"aaphp",
256
+        "Key"=>"multi.zip",
257
+        "Options"=>array("uploadId"=>$uploadid),
258
+        "Parts"=>$parts["Parts"]
259
+        );
260
+    $result = $client->completeMultipartUpload($args);
261
+    print_r($result);
262 262
 }
263 263
 function abortMultipartUpload($client){
264
-	$args=array(
265
-		"Bucket"=>"aaphp",
266
-		"Key"=>"multi.zip",
267
-		"Options"=>array("uploadId"=>"1234")
268
-		);
269
-	return $client->abortMultipartUpload($args);
264
+    $args=array(
265
+        "Bucket"=>"aaphp",
266
+        "Key"=>"multi.zip",
267
+        "Options"=>array("uploadId"=>"1234")
268
+        );
269
+    return $client->abortMultipartUpload($args);
270 270
 }
271 271
 function generatePresignedUrl($client){
272
-	$args=array(
273
-		"Bucket"=>"aaphp",
274
-		"Key"=>"multi.zip",
275
-		"Options"=>array(
276
-			"Expires"=>60*60*24*10,
277
-			"response-content-type"=>"application/xml"
278
-			)
279
-		);
280
-	return $client->generatePresignedUrl($args);
272
+    $args=array(
273
+        "Bucket"=>"aaphp",
274
+        "Key"=>"multi.zip",
275
+        "Options"=>array(
276
+            "Expires"=>60*60*24*10,
277
+            "response-content-type"=>"application/xml"
278
+            )
279
+        );
280
+    return $client->generatePresignedUrl($args);
281 281
 }
282 282
 function putObjectWithAdpAndCallBack($client){
283
-	$content = "D://野生动物.3gp";
284
-	$args = array(
285
-		"Bucket"=>"aaphp",
286
-		"Key"=>"野生动物.3gp",
287
-		"ACL"=>"public-read",
288
-		"Content"=>array(
289
-			"content"=>$content
290
-			),
291
-		"Adp"=>array(
292
-			"NotifyURL"=>"http://10.4.2.38:19090/",
293
-			"Adps"=>array(
294
-				array(
295
-					"Command"=>"tag=avop&f=mp4&res=1280x720&vbr=1000k&abr=128k",
296
-					"Key"=>"野生动物-转码.3gp"
297
-				)
298
-			)
299
-		),
300
-		"CallBack"=>array(
301
-			"Url"=>"http://10.4.2.38:19090/",
302
-			"BodyMagicVariables"=>array("bucket"=>"bucket","key"=>"key"),
303
-			"BodyVariables"=>array("name"=>"lijunwei")
304
-		)
305
-	);
306
-	return $client->putObjectByFile($args);
283
+    $content = "D://野生动物.3gp";
284
+    $args = array(
285
+        "Bucket"=>"aaphp",
286
+        "Key"=>"野生动物.3gp",
287
+        "ACL"=>"public-read",
288
+        "Content"=>array(
289
+            "content"=>$content
290
+            ),
291
+        "Adp"=>array(
292
+            "NotifyURL"=>"http://10.4.2.38:19090/",
293
+            "Adps"=>array(
294
+                array(
295
+                    "Command"=>"tag=avop&f=mp4&res=1280x720&vbr=1000k&abr=128k",
296
+                    "Key"=>"野生动物-转码.3gp"
297
+                )
298
+            )
299
+        ),
300
+        "CallBack"=>array(
301
+            "Url"=>"http://10.4.2.38:19090/",
302
+            "BodyMagicVariables"=>array("bucket"=>"bucket","key"=>"key"),
303
+            "BodyVariables"=>array("name"=>"lijunwei")
304
+        )
305
+    );
306
+    return $client->putObjectByFile($args);
307 307
 }
308 308
 function  multipartUploadWithAdpAndCallBack($client){
309
-	$args = array(
310
-		"Bucket"=>"aaphp",
311
-		"Key"=>"multi.zip",
312
-		"UserMeta"=>array(
313
-			"x-kss-meta-test"=>"example"
314
-			),
315
-		"ObjectMeta"=>array(
316
-			"Content-Type"=>"text/plain"
317
-			)
318
-		);
319
-	$uploadid = $client->initMultipartUpload($args);
320
-	print_r($uploadid);
321
-	$uploadid = $uploadid["UploadId"];
322
-	echo $uploadid."\r\n";
323
-	//开始上传
309
+    $args = array(
310
+        "Bucket"=>"aaphp",
311
+        "Key"=>"multi.zip",
312
+        "UserMeta"=>array(
313
+            "x-kss-meta-test"=>"example"
314
+            ),
315
+        "ObjectMeta"=>array(
316
+            "Content-Type"=>"text/plain"
317
+            )
318
+        );
319
+    $uploadid = $client->initMultipartUpload($args);
320
+    print_r($uploadid);
321
+    $uploadid = $uploadid["UploadId"];
322
+    echo $uploadid."\r\n";
323
+    //开始上传
324 324
 
325
-	$file = "D://野生动物.3gp";
326
-	if(Utils::chk_chinese($file)){
327
-		$file = iconv('utf-8','gbk',$file);
328
-	}
329
-	$partsize = 1024*1024*5;
330
-	$total = Utils::getFileSize($file);
331
-	$count = (int)(($total-1)/$partsize)+1;
332
-	echo $count."\r\n";
333
-	for($i = 0;$i < $count;$i++){
334
-		echo "upload".$i."\r\n";
335
-		$args=array(
336
-			"Bucket"=>"aaphp",
337
-			"Key"=>"multi.zip",
338
-			"Options"=>array(
339
-				"partNumber"=>$i+1,
340
-				"uploadId"=>$uploadid
341
-				),
342
-			"ObjectMeta"=>array(
343
-				"Content-Length"=>$partsize
344
-				),
345
-			"Content"=>array(
346
-				"content"=>$file,
347
-				"seek_position"=>$partsize*$i
348
-				)
349
-			);
350
-		$etag = $client->uploadPart($args);
351
-		print_r($etag);
352
-		$etag = $etag["ETag"];
353
-	}
354
-	$parts = $client->listParts(array("Bucket"=>"aaphp","Key"=>"multi.zip","Options"=>array("uploadId"=>$uploadid)));
355
-	print_r($parts);
356
-	//结束上传
357
-	$args=array(
358
-		"Bucket"=>"aaphp",
359
-		"Key"=>"multi.zip",
360
-		"Options"=>array("uploadId"=>$uploadid),
361
-		"Parts"=>$parts["Parts"],
362
-		"Adp"=>array(
363
-			"NotifyURL"=>"http://10.4.2.38:19090/",
364
-			"Adps"=>array(
365
-				array(
366
-					"Command"=>"tag=avop&f=mp4&res=1280x720&vbr=1000k&abr=128k",
367
-					"Key"=>"野生动物-转码.3gp"
368
-				)
369
-			)
370
-		),
371
-		"CallBack"=>array(
372
-			"Url"=>"http://10.4.2.38:19090/",
373
-			"BodyMagicVariables"=>array("bucket"=>"bucket","key"=>"key"),
374
-			"BodyVariables"=>array("name"=>"lijunwei")
375
-		)
376
-	);
377
-	$result = $client->completeMultipartUpload($args);
378
-	print_r($result);
379
-	$taskid = $result["TaskID"];
380
-	$task = $client->getAdp(array("TaskID"=>$taskid));
381
-	print_r($task);
325
+    $file = "D://野生动物.3gp";
326
+    if(Utils::chk_chinese($file)){
327
+        $file = iconv('utf-8','gbk',$file);
328
+    }
329
+    $partsize = 1024*1024*5;
330
+    $total = Utils::getFileSize($file);
331
+    $count = (int)(($total-1)/$partsize)+1;
332
+    echo $count."\r\n";
333
+    for($i = 0;$i < $count;$i++){
334
+        echo "upload".$i."\r\n";
335
+        $args=array(
336
+            "Bucket"=>"aaphp",
337
+            "Key"=>"multi.zip",
338
+            "Options"=>array(
339
+                "partNumber"=>$i+1,
340
+                "uploadId"=>$uploadid
341
+                ),
342
+            "ObjectMeta"=>array(
343
+                "Content-Length"=>$partsize
344
+                ),
345
+            "Content"=>array(
346
+                "content"=>$file,
347
+                "seek_position"=>$partsize*$i
348
+                )
349
+            );
350
+        $etag = $client->uploadPart($args);
351
+        print_r($etag);
352
+        $etag = $etag["ETag"];
353
+    }
354
+    $parts = $client->listParts(array("Bucket"=>"aaphp","Key"=>"multi.zip","Options"=>array("uploadId"=>$uploadid)));
355
+    print_r($parts);
356
+    //结束上传
357
+    $args=array(
358
+        "Bucket"=>"aaphp",
359
+        "Key"=>"multi.zip",
360
+        "Options"=>array("uploadId"=>$uploadid),
361
+        "Parts"=>$parts["Parts"],
362
+        "Adp"=>array(
363
+            "NotifyURL"=>"http://10.4.2.38:19090/",
364
+            "Adps"=>array(
365
+                array(
366
+                    "Command"=>"tag=avop&f=mp4&res=1280x720&vbr=1000k&abr=128k",
367
+                    "Key"=>"野生动物-转码.3gp"
368
+                )
369
+            )
370
+        ),
371
+        "CallBack"=>array(
372
+            "Url"=>"http://10.4.2.38:19090/",
373
+            "BodyMagicVariables"=>array("bucket"=>"bucket","key"=>"key"),
374
+            "BodyVariables"=>array("name"=>"lijunwei")
375
+        )
376
+    );
377
+    $result = $client->completeMultipartUpload($args);
378
+    print_r($result);
379
+    $taskid = $result["TaskID"];
380
+    $task = $client->getAdp(array("TaskID"=>$taskid));
381
+    print_r($task);
382 382
 }
383 383
 function putAdp($client){
384
-	$args=array(
385
-		"Bucket"=>"aaphp",
386
-		"Key"=>"multi.zip",
387
-		"Adp"=>array(
388
-			"NotifyURL"=>"http://10.4.2.38:19090/",
389
-			"Adps"=>array(
390
-				array(
391
-					"Command"=>"tag=avop&f=mp4&res=1280x720&vbr=1000k&abr=128k",
392
-					"Key"=>"野生动物-转码.3gp"
393
-				)
394
-			)
395
-		)
396
-	);
397
-	$result = $client->putAdp($args);
398
-	print_r($result);
399
-	$taskid = $result["TaskID"];
400
-	$task = $client->getAdp(array("TaskID"=>$taskid));
401
-	print_r($task);
384
+    $args=array(
385
+        "Bucket"=>"aaphp",
386
+        "Key"=>"multi.zip",
387
+        "Adp"=>array(
388
+            "NotifyURL"=>"http://10.4.2.38:19090/",
389
+            "Adps"=>array(
390
+                array(
391
+                    "Command"=>"tag=avop&f=mp4&res=1280x720&vbr=1000k&abr=128k",
392
+                    "Key"=>"野生动物-转码.3gp"
393
+                )
394
+            )
395
+        )
396
+    );
397
+    $result = $client->putAdp($args);
398
+    print_r($result);
399
+    $taskid = $result["TaskID"];
400
+    $task = $client->getAdp(array("TaskID"=>$taskid));
401
+    print_r($task);
402 402
 }
403 403
 function postObject($client){
404 404
 
405
-	$postData = array(
406
-		"key"=>"~!@\\#$\%^&*()_+-=qw",
407
-		"acl"=>"public-read"
408
-		);
409
-	$unKnowData=array("122","334");
405
+    $postData = array(
406
+        "key"=>"~!@\\#$\%^&*()_+-=qw",
407
+        "acl"=>"public-read"
408
+        );
409
+    $unKnowData=array("122","334");
410 410
 
411
-	print_r($client->postObject("ksc-scm",$postData,$unKnowData));
411
+    print_r($client->postObject("ksc-scm",$postData,$unKnowData));
412 412
 }
413 413
 ?>
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 require_once "../Ks3Client.class.php";
3 3
 require_once "../core/Utils.class.php";
4 4
 
5
-$client = new Ks3Client("","","kss.ksyun.com");//!!第三个参数endpoint需要对应bucket所在region!! 详见http://ks3.ksyun.com/doc/api/index.html  Region(区域)一节
5
+$client = new Ks3Client("", "", "kss.ksyun.com"); //!!第三个参数endpoint需要对应bucket所在region!! 详见http://ks3.ksyun.com/doc/api/index.html  Region(区域)一节
6 6
 //print_r(listBuckets($client));
7 7
 //print_r(deleteBucket($client));
8 8
 //print_r(deleteBucketCORS($client));
@@ -32,16 +32,16 @@  discard block
 block discarded – undo
32 32
 //print_r(multipartUploadWithAdpAndCallBack($client));
33 33
 //print_r(putAdp($client));
34 34
 //print_r(postObject($client));
35
-function listBuckets($client){
35
+function listBuckets($client) {
36 36
 	return $client->listBuckets();
37 37
 }
38
-function deleteBucket($client){
38
+function deleteBucket($client) {
39 39
 	return $client->deleteBucket(array("Bucket"=>"ksc-scm"));
40 40
 }
41
-function deleteBucketCORS($client){
41
+function deleteBucketCORS($client) {
42 42
 	return $client->deleteBucketCORS(array("Bucket"=>"ksc-scm"));
43 43
 }
44
-function listObjects($client){
44
+function listObjects($client) {
45 45
 	$args = array(
46 46
 		"Bucket"=>"lijunwei.test",
47 47
 		"Options"=>array(
@@ -53,49 +53,49 @@  discard block
 block discarded – undo
53 53
 		);
54 54
 	return $client->listObjects($args);
55 55
 }
56
-function getBucketAcl($client){
56
+function getBucketAcl($client) {
57 57
 	return $client->getBucketAcl(array("Bucket"=>"aaphp"));
58 58
 }
59
-function getBucketCORS($client){
59
+function getBucketCORS($client) {
60 60
 	return $client->getBucketCORS(array("Bucket"=>"ksc-scm"));
61 61
 }
62
-function getBucketLocation($client){
62
+function getBucketLocation($client) {
63 63
 	return $client->getBucketLocation(array("Bucket"=>"ksc-scm"));
64 64
 }
65
-function getBucketLogging($client){
65
+function getBucketLogging($client) {
66 66
 	return $client->getBucketLogging(array("Bucket"=>"ksc-scm"));
67 67
 }
68
-function bucketExists($client){
68
+function bucketExists($client) {
69 69
 	$args = array("Bucket"=>"ksc-scm");
70 70
 	return $client->bucketExists($args);
71 71
 }
72
-function createBucket($client){
72
+function createBucket($client) {
73 73
 	$args = array(
74 74
 		"Bucket"=>"ksc-scm",
75 75
 		"ACL"=>"private"
76 76
 		);
77 77
 	return $client->createBucket($args);
78 78
 }
79
-function setBucketAcl($client){
79
+function setBucketAcl($client) {
80 80
 	$args = array(
81 81
 		"Bucket"=>"ksc-scm",
82 82
 		"ACL"=>"private"
83 83
 		);
84 84
 	return $client->setBucketAcl($args);
85 85
 }
86
-function setBucketCORS($client){
86
+function setBucketCORS($client) {
87 87
 	$args = array(
88 88
 		"Bucket"=>"ksc-scm",
89 89
 		"CORS"=>array(
90 90
 			array(
91
-				"AllowedMethod"=>array("GET","PUT"),
91
+				"AllowedMethod"=>array("GET", "PUT"),
92 92
 				"AllowedOrigin"=>array("http://www.kingsoft.com"),
93 93
 				"AllowedHeader"=>array("*"),
94 94
 				"ExposeHeader"=>array("*"),
95 95
 				"MaxAgeSeconds"=>10
96 96
 			),
97 97
 			array(
98
-				"AllowedMethod"=>array("GET","PUT"),
98
+				"AllowedMethod"=>array("GET", "PUT"),
99 99
 				"AllowedOrigin"=>array("*"),
100 100
 				"AllowedHeader"=>array("*"),
101 101
 				"ExposeHeader"=>array("*"),
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	);
106 106
 	return $client->setBucketCORS($args);
107 107
 }
108
-function setBucketLogging($client){
108
+function setBucketLogging($client) {
109 109
 	$args = array(
110 110
 		"Bucket"=>"ksc-scm",
111 111
 		"BucketLogging"=>array(
@@ -116,21 +116,21 @@  discard block
 block discarded – undo
116 116
 		);
117 117
 	return $client->setBucketLogging($args);
118 118
 }
119
-function deleteObject($client){
119
+function deleteObject($client) {
120 120
 	$args = array(
121 121
 		"Bucket"=>"ksc-scm",
122 122
 		"Key"=>"123.pdf"
123 123
 		);
124 124
 	return $client->deleteObject($args);
125 125
 }
126
-function deleteObjects($client){
126
+function deleteObjects($client) {
127 127
 	$args = array(
128 128
 		"Bucket"=>"ksc-scm",
129
-		"DeleteKeys"=>array("copy/test.zip","copy/123.doc")
129
+		"DeleteKeys"=>array("copy/test.zip", "copy/123.doc")
130 130
 		);
131 131
 	return $client->deleteObjects($args);
132 132
 }
133
-function getObject($client){
133
+function getObject($client) {
134 134
 	$args = array(
135 135
 		"Bucket"=>"aaphp",
136 136
 		"Key"=>"multi.exe",
@@ -142,28 +142,28 @@  discard block
 block discarded – undo
142 142
 		);
143 143
 	return $client->getObject($args);
144 144
 }
145
-function getObjectAcl($client){
145
+function getObjectAcl($client) {
146 146
 	$args = array(
147 147
 		"Bucket"=>"aaphp",
148 148
 		"Key"=>"multi.exe"
149 149
 		);
150 150
 	return $client->getObjectAcl($args);
151 151
 }
152
-function objectExists($client){
152
+function objectExists($client) {
153 153
 	$args = array(
154 154
 		"Bucket"=>"ksc-scm",
155 155
 		"Key"=>"123.pdf"
156 156
 		);
157 157
 	return $client->objectExists($args);
158 158
 }
159
-function getObjectMeta($client){
159
+function getObjectMeta($client) {
160 160
 	$args = array(
161 161
 		"Bucket"=>"aaphp",
162 162
 		"Key"=>"test.zip"
163 163
 		);
164 164
 	return $client->getObjectMeta($args);
165 165
 }
166
-function setObjectAcl($client){
166
+function setObjectAcl($client) {
167 167
 	$args = array(
168 168
 		"Bucket"=>"aaphp",
169 169
 		"Key"=>"test.zip",
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 		);
172 172
 	return $client->setObjectAcl($args);
173 173
 }
174
-function copyObject($client){
174
+function copyObject($client) {
175 175
 	$args = array(
176 176
 		"Bucket"=>"aaphp",
177 177
 		"Key"=>"copy/test.zip",
@@ -182,10 +182,10 @@  discard block
 block discarded – undo
182 182
 		);
183 183
 	return $client->copyObject($args);
184 184
 }
185
-function putObjectByFile($client){
185
+function putObjectByFile($client) {
186 186
 	$file = "D://phpput";
187
-	if(Utils::chk_chinese($file)){
188
-		$file = iconv('utf-8','gbk',$file);
187
+	if (Utils::chk_chinese($file)) {
188
+		$file = iconv('utf-8', 'gbk', $file);
189 189
 	}
190 190
 	$content = $file;
191 191
 	$args = array(
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 		"Key"=>"stream_upload1.txt",
194 194
 		"ACL"=>"public-read",
195 195
 		"ObjectMeta"=>array(
196
-			"Content-Type"=>"image/jpg",//只传0-10字节,
196
+			"Content-Type"=>"image/jpg", //只传0-10字节,
197 197
 			),
198 198
 		"Content"=>array(
199 199
 			"content"=>$file,
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 	);
203 203
 	return $client->putObjectByFile($args);
204 204
 }
205
-function multipartUpload($client){
205
+function multipartUpload($client) {
206 206
 	$args = array(
207 207
 		"Bucket"=>"aaphp",
208 208
 		"Key"=>"multi.zip",
@@ -220,16 +220,16 @@  discard block
 block discarded – undo
220 220
 	//开始上传
221 221
 
222 222
 	$file = "D://新建文件夹.rar";
223
-	if(Utils::chk_chinese($file)){
224
-		$file = iconv('utf-8','gbk',$file);
223
+	if (Utils::chk_chinese($file)) {
224
+		$file = iconv('utf-8', 'gbk', $file);
225 225
 	}
226 226
 	$total = Utils::getFileSize($file);
227 227
 	$partsize = 1024*1024*5;
228 228
 	$count = (int)(($total-1)/$partsize)+1;
229 229
 	echo $count."\r\n";
230
-	for($i = 0;$i < $count;$i++){
230
+	for ($i = 0; $i < $count; $i++) {
231 231
 		echo "upload".$i."\r\n";
232
-		$args=array(
232
+		$args = array(
233 233
 			"Bucket"=>"aaphp",
234 234
 			"Key"=>"multi.zip",
235 235
 			"Options"=>array(
@@ -248,10 +248,10 @@  discard block
 block discarded – undo
248 248
 		print_r($etag);
249 249
 		$etag = $etag["ETag"];
250 250
 	}
251
-	$parts = $client->listParts(array("Bucket"=>"aaphp","Key"=>"multi.zip","Options"=>array("uploadId"=>$uploadid)));
251
+	$parts = $client->listParts(array("Bucket"=>"aaphp", "Key"=>"multi.zip", "Options"=>array("uploadId"=>$uploadid)));
252 252
 	print_r($parts);
253 253
 	//结束上传
254
-	$args=array(
254
+	$args = array(
255 255
 		"Bucket"=>"aaphp",
256 256
 		"Key"=>"multi.zip",
257 257
 		"Options"=>array("uploadId"=>$uploadid),
@@ -260,16 +260,16 @@  discard block
 block discarded – undo
260 260
 	$result = $client->completeMultipartUpload($args);
261 261
 	print_r($result);
262 262
 }
263
-function abortMultipartUpload($client){
264
-	$args=array(
263
+function abortMultipartUpload($client) {
264
+	$args = array(
265 265
 		"Bucket"=>"aaphp",
266 266
 		"Key"=>"multi.zip",
267 267
 		"Options"=>array("uploadId"=>"1234")
268 268
 		);
269 269
 	return $client->abortMultipartUpload($args);
270 270
 }
271
-function generatePresignedUrl($client){
272
-	$args=array(
271
+function generatePresignedUrl($client) {
272
+	$args = array(
273 273
 		"Bucket"=>"aaphp",
274 274
 		"Key"=>"multi.zip",
275 275
 		"Options"=>array(
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 		);
280 280
 	return $client->generatePresignedUrl($args);
281 281
 }
282
-function putObjectWithAdpAndCallBack($client){
282
+function putObjectWithAdpAndCallBack($client) {
283 283
 	$content = "D://野生动物.3gp";
284 284
 	$args = array(
285 285
 		"Bucket"=>"aaphp",
@@ -299,13 +299,13 @@  discard block
 block discarded – undo
299 299
 		),
300 300
 		"CallBack"=>array(
301 301
 			"Url"=>"http://10.4.2.38:19090/",
302
-			"BodyMagicVariables"=>array("bucket"=>"bucket","key"=>"key"),
302
+			"BodyMagicVariables"=>array("bucket"=>"bucket", "key"=>"key"),
303 303
 			"BodyVariables"=>array("name"=>"lijunwei")
304 304
 		)
305 305
 	);
306 306
 	return $client->putObjectByFile($args);
307 307
 }
308
-function  multipartUploadWithAdpAndCallBack($client){
308
+function  multipartUploadWithAdpAndCallBack($client) {
309 309
 	$args = array(
310 310
 		"Bucket"=>"aaphp",
311 311
 		"Key"=>"multi.zip",
@@ -323,16 +323,16 @@  discard block
 block discarded – undo
323 323
 	//开始上传
324 324
 
325 325
 	$file = "D://野生动物.3gp";
326
-	if(Utils::chk_chinese($file)){
327
-		$file = iconv('utf-8','gbk',$file);
326
+	if (Utils::chk_chinese($file)) {
327
+		$file = iconv('utf-8', 'gbk', $file);
328 328
 	}
329 329
 	$partsize = 1024*1024*5;
330 330
 	$total = Utils::getFileSize($file);
331 331
 	$count = (int)(($total-1)/$partsize)+1;
332 332
 	echo $count."\r\n";
333
-	for($i = 0;$i < $count;$i++){
333
+	for ($i = 0; $i < $count; $i++) {
334 334
 		echo "upload".$i."\r\n";
335
-		$args=array(
335
+		$args = array(
336 336
 			"Bucket"=>"aaphp",
337 337
 			"Key"=>"multi.zip",
338 338
 			"Options"=>array(
@@ -351,10 +351,10 @@  discard block
 block discarded – undo
351 351
 		print_r($etag);
352 352
 		$etag = $etag["ETag"];
353 353
 	}
354
-	$parts = $client->listParts(array("Bucket"=>"aaphp","Key"=>"multi.zip","Options"=>array("uploadId"=>$uploadid)));
354
+	$parts = $client->listParts(array("Bucket"=>"aaphp", "Key"=>"multi.zip", "Options"=>array("uploadId"=>$uploadid)));
355 355
 	print_r($parts);
356 356
 	//结束上传
357
-	$args=array(
357
+	$args = array(
358 358
 		"Bucket"=>"aaphp",
359 359
 		"Key"=>"multi.zip",
360 360
 		"Options"=>array("uploadId"=>$uploadid),
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 		),
371 371
 		"CallBack"=>array(
372 372
 			"Url"=>"http://10.4.2.38:19090/",
373
-			"BodyMagicVariables"=>array("bucket"=>"bucket","key"=>"key"),
373
+			"BodyMagicVariables"=>array("bucket"=>"bucket", "key"=>"key"),
374 374
 			"BodyVariables"=>array("name"=>"lijunwei")
375 375
 		)
376 376
 	);
@@ -380,8 +380,8 @@  discard block
 block discarded – undo
380 380
 	$task = $client->getAdp(array("TaskID"=>$taskid));
381 381
 	print_r($task);
382 382
 }
383
-function putAdp($client){
384
-	$args=array(
383
+function putAdp($client) {
384
+	$args = array(
385 385
 		"Bucket"=>"aaphp",
386 386
 		"Key"=>"multi.zip",
387 387
 		"Adp"=>array(
@@ -400,14 +400,14 @@  discard block
 block discarded – undo
400 400
 	$task = $client->getAdp(array("TaskID"=>$taskid));
401 401
 	print_r($task);
402 402
 }
403
-function postObject($client){
403
+function postObject($client) {
404 404
 
405 405
 	$postData = array(
406 406
 		"key"=>"~!@\\#$\%^&*()_+-=qw",
407 407
 		"acl"=>"public-read"
408 408
 		);
409
-	$unKnowData=array("122","334");
409
+	$unKnowData = array("122", "334");
410 410
 
411
-	print_r($client->postObject("ksc-scm",$postData,$unKnowData));
411
+	print_r($client->postObject("ksc-scm", $postData, $unKnowData));
412 412
 }
413 413
 ?>
Please login to merge, or discard this patch.
src/service/ksyun/bin/encryption/EncryptionUtil.php 3 patches
Indentation   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -1,279 +1,279 @@
 block discarded – undo
1 1
 <?php
2 2
 class EncryptionUtil{
3
-	public static $INSTRUCTION_SUFFIX = ".instruction";
4
-	public static function genereateOnceUsedKey($length=32){
5
-		$randpwd = "";  
6
-		for ($i = 0; $i < $length; $i++)  
7
-		{  
8
-			$randpwd .= chr(mt_rand(33, 126));  
9
-		}  
10
-		return $randpwd;   
11
-	}
12
-	public static function encode_AES_ECB($data,$secret_key){
13
-		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_ECB,'');
3
+    public static $INSTRUCTION_SUFFIX = ".instruction";
4
+    public static function genereateOnceUsedKey($length=32){
5
+        $randpwd = "";  
6
+        for ($i = 0; $i < $length; $i++)  
7
+        {  
8
+            $randpwd .= chr(mt_rand(33, 126));  
9
+        }  
10
+        return $randpwd;   
11
+    }
12
+    public static function encode_AES_ECB($data,$secret_key){
13
+        $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_ECB,'');
14 14
 
15
-		$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_ECB);
16
-		$pad = $blocksize - (strlen($data) % $blocksize);
17
-		$data = $data . str_repeat(chr($pad), $pad);
15
+        $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_ECB);
16
+        $pad = $blocksize - (strlen($data) % $blocksize);
17
+        $data = $data . str_repeat(chr($pad), $pad);
18 18
 
19
-		$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
20
-		mcrypt_generic_init($td,$secret_key,$iv);
21
-		$encrypted = mcrypt_generic($td,$data);
22
-		mcrypt_generic_deinit($td);
23
-		return $encrypted;
24
-	}
25
-	public static function decode_AES_ECB($data,$secret_key){
26
-		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_ECB,'');
27
-		$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
28
-		mcrypt_generic_init($td,$secret_key,$iv);
29
-		$data = mdecrypt_generic($td,$data);
30
-		mcrypt_generic_deinit($td);
31
-		mcrypt_module_close($td);
19
+        $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
20
+        mcrypt_generic_init($td,$secret_key,$iv);
21
+        $encrypted = mcrypt_generic($td,$data);
22
+        mcrypt_generic_deinit($td);
23
+        return $encrypted;
24
+    }
25
+    public static function decode_AES_ECB($data,$secret_key){
26
+        $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_ECB,'');
27
+        $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
28
+        mcrypt_generic_init($td,$secret_key,$iv);
29
+        $data = mdecrypt_generic($td,$data);
30
+        mcrypt_generic_deinit($td);
31
+        mcrypt_module_close($td);
32 32
 
33
-		$dec_s = strlen($data);
34
-		$padding = ord($data[$dec_s-1]);
35
-		$data = substr($data, 0, -$padding);
33
+        $dec_s = strlen($data);
34
+        $padding = ord($data[$dec_s-1]);
35
+        $data = substr($data, 0, -$padding);
36 36
 
37
-		return trim($data);
38
-	}
39
-	public static function getKeyEncryptionAlgm($encryptionMaterials){
40
-		if(is_array($encryptionMaterials)){
41
-			return "RSA";
42
-		}else{
43
-			return "AES";
44
-		}
45
-	}
46
-	public static function getAdjustedRange($range,$blocksize){
47
-		$a = $range["start"];
48
-		$b = $range["end"];
49
-		$a = $a - ($a%$blocksize)-$blocksize;
50
-		if($a < 0)
51
-			$a = 0;
37
+        return trim($data);
38
+    }
39
+    public static function getKeyEncryptionAlgm($encryptionMaterials){
40
+        if(is_array($encryptionMaterials)){
41
+            return "RSA";
42
+        }else{
43
+            return "AES";
44
+        }
45
+    }
46
+    public static function getAdjustedRange($range,$blocksize){
47
+        $a = $range["start"];
48
+        $b = $range["end"];
49
+        $a = $a - ($a%$blocksize)-$blocksize;
50
+        if($a < 0)
51
+            $a = 0;
52 52
 
53
-		$b = $b+$blocksize-$b%$blocksize+$blocksize;
53
+        $b = $b+$blocksize-$b%$blocksize+$blocksize;
54 54
 
55
-		return array("start"=>$a,"end"=>$b);
56
-	}
57
-	public static function encodeCek($encryptionMaterials,$cek){
58
-		$encrypKeyAlg = EncryptionUtil::getKeyEncryptionAlgm($encryptionMaterials);
59
-		if($encrypKeyAlg === "AES"){
60
-			$secretKey = $encryptionMaterials;
61
-			$encryptedSek = EncryptionUtil::encode_AES_ECB($cek,$secretKey);
62
-			if(empty($encryptedSek))
63
-				throw new Ks3ClientException("can not encode cek useing AES");
64
-		}else if($encrypKeyAlg === "RSA"){
65
-			$encryptedSek = "";
66
-			openssl_public_encrypt($cek,$encryptedSek, $encryptionMaterials[0]);
67
-			if(empty($encryptedSek))
68
-				throw new Ks3ClientException("can not encode cek useing RSA");
69
-		}
70
-		return $encryptedSek;
71
-	}
72
-	public static function decodeCek($encryptionMaterials,$cekEncrypted){
73
-		$encrypKeyAlg = EncryptionUtil::getKeyEncryptionAlgm($encryptionMaterials);
74
-		if($encrypKeyAlg === "AES"){
75
-			$secretKey = $encryptionMaterials;
76
-			$cek = EncryptionUtil::decode_AES_ECB($cekEncrypted,$secretKey);
77
-			if(empty($cek))
78
-				throw new Ks3ClientException("can not decode cek useing AES,secret key maybe not correct");
79
-		}else if($encrypKeyAlg === "RSA"){
80
-			$cek = "";
81
-			openssl_private_decrypt($cekEncrypted,$cek, $encryptionMaterials[1]);
82
-			if(empty($cek))
83
-				throw new Ks3ClientException("can not decode cek useing RSA,public/private key pair maybe not correct");
84
-		}
85
-		return $cek;
86
-	}
87
-	public static function getPKCS5EncrypedLength($length,$blocksize){
88
-		$pad = $blocksize - $length%$blocksize;
89
-		return $length+$pad;
90
-	}
91
-	//pkcs5填充
92
-	public static function PKCS5Padding($data,$blocksize){
93
-		$pad = $blocksize - strlen($data)%$blocksize;
94
-		for($i = 0;$i < $pad;$i++){
95
-			$data.= chr($pad);
96
-		}
97
-		return $data;
98
-	}
99
-	public static function updateContentMD5Header($req){
100
-		if(!is_array($req))
101
-			return $req;
102
-		if(isset($req["ObjectMeta"])){
103
-			$meta = $req["ObjectMeta"];
104
-		}else{
105
-			return $req;
106
-		}
107
-		if(is_array($meta) && isset($meta["Content-MD5"])){
108
-			$md5 = $meta["Content-MD5"];
109
-		}else{
110
-			return $req;
111
-		}
112
-		if(empty($md5)){
113
-			return $req;
114
-		}else{
115
-			$req["ObjectMeta"]["Content-MD5"] = NULL;
116
-			$req["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-md5"] = $md5;
117
-		}
118
-		return $req;
119
-	}
120
-	public static function metaTextLength($req){
121
-		if(!is_array($req))
122
-			return -1;
123
-		if(isset($req["ObjectMeta"])){
124
-			$meta = $req["ObjectMeta"];
125
-		}else{
126
-			return -1;
127
-		}
128
-		if(is_array($meta) && isset($meta["Content-Length"])){
129
-			$length = $meta["Content-Length"];
130
-			return $length;
131
-		}else
132
-			return -1;
133
-	}
134
-	public static function plainTextLength($args){
135
-		if(isset($args["Content"])){
136
-			if(is_array($args["Content"])){
137
-				$content = $args["Content"]["content"];
138
-				$seek_position = 0;
139
-				$resourceLength = 0;
140
-				$length = -1;
141
-				$isFile = FALSE;
55
+        return array("start"=>$a,"end"=>$b);
56
+    }
57
+    public static function encodeCek($encryptionMaterials,$cek){
58
+        $encrypKeyAlg = EncryptionUtil::getKeyEncryptionAlgm($encryptionMaterials);
59
+        if($encrypKeyAlg === "AES"){
60
+            $secretKey = $encryptionMaterials;
61
+            $encryptedSek = EncryptionUtil::encode_AES_ECB($cek,$secretKey);
62
+            if(empty($encryptedSek))
63
+                throw new Ks3ClientException("can not encode cek useing AES");
64
+        }else if($encrypKeyAlg === "RSA"){
65
+            $encryptedSek = "";
66
+            openssl_public_encrypt($cek,$encryptedSek, $encryptionMaterials[0]);
67
+            if(empty($encryptedSek))
68
+                throw new Ks3ClientException("can not encode cek useing RSA");
69
+        }
70
+        return $encryptedSek;
71
+    }
72
+    public static function decodeCek($encryptionMaterials,$cekEncrypted){
73
+        $encrypKeyAlg = EncryptionUtil::getKeyEncryptionAlgm($encryptionMaterials);
74
+        if($encrypKeyAlg === "AES"){
75
+            $secretKey = $encryptionMaterials;
76
+            $cek = EncryptionUtil::decode_AES_ECB($cekEncrypted,$secretKey);
77
+            if(empty($cek))
78
+                throw new Ks3ClientException("can not decode cek useing AES,secret key maybe not correct");
79
+        }else if($encrypKeyAlg === "RSA"){
80
+            $cek = "";
81
+            openssl_private_decrypt($cekEncrypted,$cek, $encryptionMaterials[1]);
82
+            if(empty($cek))
83
+                throw new Ks3ClientException("can not decode cek useing RSA,public/private key pair maybe not correct");
84
+        }
85
+        return $cek;
86
+    }
87
+    public static function getPKCS5EncrypedLength($length,$blocksize){
88
+        $pad = $blocksize - $length%$blocksize;
89
+        return $length+$pad;
90
+    }
91
+    //pkcs5填充
92
+    public static function PKCS5Padding($data,$blocksize){
93
+        $pad = $blocksize - strlen($data)%$blocksize;
94
+        for($i = 0;$i < $pad;$i++){
95
+            $data.= chr($pad);
96
+        }
97
+        return $data;
98
+    }
99
+    public static function updateContentMD5Header($req){
100
+        if(!is_array($req))
101
+            return $req;
102
+        if(isset($req["ObjectMeta"])){
103
+            $meta = $req["ObjectMeta"];
104
+        }else{
105
+            return $req;
106
+        }
107
+        if(is_array($meta) && isset($meta["Content-MD5"])){
108
+            $md5 = $meta["Content-MD5"];
109
+        }else{
110
+            return $req;
111
+        }
112
+        if(empty($md5)){
113
+            return $req;
114
+        }else{
115
+            $req["ObjectMeta"]["Content-MD5"] = NULL;
116
+            $req["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-md5"] = $md5;
117
+        }
118
+        return $req;
119
+    }
120
+    public static function metaTextLength($req){
121
+        if(!is_array($req))
122
+            return -1;
123
+        if(isset($req["ObjectMeta"])){
124
+            $meta = $req["ObjectMeta"];
125
+        }else{
126
+            return -1;
127
+        }
128
+        if(is_array($meta) && isset($meta["Content-Length"])){
129
+            $length = $meta["Content-Length"];
130
+            return $length;
131
+        }else
132
+            return -1;
133
+    }
134
+    public static function plainTextLength($args){
135
+        if(isset($args["Content"])){
136
+            if(is_array($args["Content"])){
137
+                $content = $args["Content"]["content"];
138
+                $seek_position = 0;
139
+                $resourceLength = 0;
140
+                $length = -1;
141
+                $isFile = FALSE;
142 142
 
143
-				if (!is_resource($content)){
144
-					$isFile = TRUE;
145
-					//如果之前用户已经转化为GBK则不转换
146
-					if(Utils::chk_chinese($content)&&!Utils::check_char($content)){
147
-						$content = iconv('utf-8','gbk',$content);
148
-					}
149
-					if(!file_exists($content))
150
-						throw new Ks3ClientException("the specified file does not exist ");
151
-					$length = Utils::getFileSize($content);
152
-					$content = fopen($content,"r");
153
-				}else{
154
-					$stats = fstat($content);
155
-					if ($stats && $stats["size"] >= 0){
156
-						$length = $stats["size"];	
157
-					}
158
-				}
159
-				$resourceLength = $length;
160
-				//优先取用户设置seek_position,没有的话取ftell
161
-				if(isset($args["Content"]["seek_position"])&&$args["Content"]["seek_position"]>0){
162
-					$seek_position = $args["Content"]["seek_position"];
163
-				}else if(!$isFile){
164
-					$seek_position = ftell($content);
165
-					if($seek_position<0)
166
-						$seek_position = 0;
167
-					fseek($content,0);
168
-				}
143
+                if (!is_resource($content)){
144
+                    $isFile = TRUE;
145
+                    //如果之前用户已经转化为GBK则不转换
146
+                    if(Utils::chk_chinese($content)&&!Utils::check_char($content)){
147
+                        $content = iconv('utf-8','gbk',$content);
148
+                    }
149
+                    if(!file_exists($content))
150
+                        throw new Ks3ClientException("the specified file does not exist ");
151
+                    $length = Utils::getFileSize($content);
152
+                    $content = fopen($content,"r");
153
+                }else{
154
+                    $stats = fstat($content);
155
+                    if ($stats && $stats["size"] >= 0){
156
+                        $length = $stats["size"];	
157
+                    }
158
+                }
159
+                $resourceLength = $length;
160
+                //优先取用户设置seek_position,没有的话取ftell
161
+                if(isset($args["Content"]["seek_position"])&&$args["Content"]["seek_position"]>0){
162
+                    $seek_position = $args["Content"]["seek_position"];
163
+                }else if(!$isFile){
164
+                    $seek_position = ftell($content);
165
+                    if($seek_position<0)
166
+                        $seek_position = 0;
167
+                    fseek($content,0);
168
+                }
169 169
 
170
-				$lengthInMeta = -1;
171
-				if(isset($args["ObjectMeta"]["Content-Length"])){
172
-					$lengthInMeta = $args["ObjectMeta"]["Content-Length"];
173
-				}
174
-				if($lengthInMeta > 0){
175
-					$length = $lengthInMeta;
176
-				}else if($resourceLength > 0){
177
-					//根据seek_position计算实际长度
178
-					$length = $resourceLength - $seek_position;
179
-				}
180
-				if($length <= 0)
181
-					throw new Ks3ClientException("calculate content length failed,unexpected contetn length ".$length);
182
-				return $length;
183
-			}else{
184
-				$content = $args["Content"];
185
-				$lengthInMeta = EncryptionUtil::metaTextLength($args);
186
-				$length = strlen($content);
187
-				if($length<$lengthInMeta||$lengthInMeta <= 0)
188
-					return $length;
189
-				else
190
-					return $lengthInMeta;
191
-			}
192
-		}
193
-		return -1;
194
-	}
195
-	public static function initMultipartUploadContext($initResult,$iv,$cek,$encryptedCek,$matdesc="{}"){
196
-		$cacheDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR;
197
-		$encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
198
-		if(!is_dir($cacheDir))
199
-			mkdir($cacheDir);
200
-		if(!is_dir($encryptionDir))
201
-			mkdir($encryptionDir);
202
-		if(is_array($matdesc)){
203
-			$matdesc = json_encode($matdesc);
204
-		}
205
-		$initResult["firstIv"] = base64_encode($iv);
206
-		$initResult["nextIv"] = base64_encode($iv);
207
-		$initResult["cek"] = base64_encode($cek);
208
-		$initResult["encryptedCek"] = base64_encode($encryptedCek);
209
-		$initResult["lastPart"] = FALSE;
210
-		$initResult["matdesc"] = $matdesc;
211
-		$json = json_encode($initResult);
212
-		$file = EncryptionUtil::openfile($encryptionDir.$initResult["UploadId"], "w");
213
-		fwrite($file, $json);
214
-		fclose($file);
215
-	}
216
-	public static function updateMultipartUploadContext($UploadId,$iv,$lastPart = FALSE){
217
-		$encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
218
-		$content = EncryptionUtil::getMultipartUploadContext($UploadId);
219
-		$content["nextIv"] = base64_encode($iv);
220
-		$content["lastPart"] = $lastPart;
221
-		$json = json_encode($content);
222
-		$file = EncryptionUtil::openfile($encryptionDir.$UploadId, "w");
223
-		fwrite($file, $json);
224
-		fclose($file);
225
-	}
226
-	public static function getMultipartUploadContext($UploadId){
227
-		$encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
228
-		if(!EncryptionUtil::multipartUploadContextExists($UploadId))
229
-			throw new Ks3ClientException("can not found multipart upload context in cache dir");
230
-		$jsonString = file_get_contents($encryptionDir.$UploadId);
231
-		$arry = json_decode($jsonString,TRUE);
232
-		return $arry;
233
-	}
234
-	public static function deleteMultipartUploadContext($UploadId){
235
-		$encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
236
-		@unlink($encryptionDir.$UploadId);
237
-	}
238
-	public static function multipartUploadContextExists($UploadId){
239
-		$encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
240
-		return file_exists($encryptionDir.$UploadId);
241
-	}
242
-	public static function openfile($path,$mode){
243
-		$file = fopen($path, $mode);
244
-		if($file)
245
-			return $file;
246
-		else
247
-			throw new Ks3ClientException("open file ".$path." error");
248
-	}
249
-	//matdesc为字符串或array数据类型。
250
-	public static function createInstructionFile($bucket,$key,$cek,$iv,$matdesc="{}"){
251
-		if(is_array($matdesc)){
252
-			$matdesc = json_encode($matdesc);
253
-		}
254
-		$key = $key.EncryptionUtil::$INSTRUCTION_SUFFIX;
170
+                $lengthInMeta = -1;
171
+                if(isset($args["ObjectMeta"]["Content-Length"])){
172
+                    $lengthInMeta = $args["ObjectMeta"]["Content-Length"];
173
+                }
174
+                if($lengthInMeta > 0){
175
+                    $length = $lengthInMeta;
176
+                }else if($resourceLength > 0){
177
+                    //根据seek_position计算实际长度
178
+                    $length = $resourceLength - $seek_position;
179
+                }
180
+                if($length <= 0)
181
+                    throw new Ks3ClientException("calculate content length failed,unexpected contetn length ".$length);
182
+                return $length;
183
+            }else{
184
+                $content = $args["Content"];
185
+                $lengthInMeta = EncryptionUtil::metaTextLength($args);
186
+                $length = strlen($content);
187
+                if($length<$lengthInMeta||$lengthInMeta <= 0)
188
+                    return $length;
189
+                else
190
+                    return $lengthInMeta;
191
+            }
192
+        }
193
+        return -1;
194
+    }
195
+    public static function initMultipartUploadContext($initResult,$iv,$cek,$encryptedCek,$matdesc="{}"){
196
+        $cacheDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR;
197
+        $encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
198
+        if(!is_dir($cacheDir))
199
+            mkdir($cacheDir);
200
+        if(!is_dir($encryptionDir))
201
+            mkdir($encryptionDir);
202
+        if(is_array($matdesc)){
203
+            $matdesc = json_encode($matdesc);
204
+        }
205
+        $initResult["firstIv"] = base64_encode($iv);
206
+        $initResult["nextIv"] = base64_encode($iv);
207
+        $initResult["cek"] = base64_encode($cek);
208
+        $initResult["encryptedCek"] = base64_encode($encryptedCek);
209
+        $initResult["lastPart"] = FALSE;
210
+        $initResult["matdesc"] = $matdesc;
211
+        $json = json_encode($initResult);
212
+        $file = EncryptionUtil::openfile($encryptionDir.$initResult["UploadId"], "w");
213
+        fwrite($file, $json);
214
+        fclose($file);
215
+    }
216
+    public static function updateMultipartUploadContext($UploadId,$iv,$lastPart = FALSE){
217
+        $encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
218
+        $content = EncryptionUtil::getMultipartUploadContext($UploadId);
219
+        $content["nextIv"] = base64_encode($iv);
220
+        $content["lastPart"] = $lastPart;
221
+        $json = json_encode($content);
222
+        $file = EncryptionUtil::openfile($encryptionDir.$UploadId, "w");
223
+        fwrite($file, $json);
224
+        fclose($file);
225
+    }
226
+    public static function getMultipartUploadContext($UploadId){
227
+        $encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
228
+        if(!EncryptionUtil::multipartUploadContextExists($UploadId))
229
+            throw new Ks3ClientException("can not found multipart upload context in cache dir");
230
+        $jsonString = file_get_contents($encryptionDir.$UploadId);
231
+        $arry = json_decode($jsonString,TRUE);
232
+        return $arry;
233
+    }
234
+    public static function deleteMultipartUploadContext($UploadId){
235
+        $encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
236
+        @unlink($encryptionDir.$UploadId);
237
+    }
238
+    public static function multipartUploadContextExists($UploadId){
239
+        $encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
240
+        return file_exists($encryptionDir.$UploadId);
241
+    }
242
+    public static function openfile($path,$mode){
243
+        $file = fopen($path, $mode);
244
+        if($file)
245
+            return $file;
246
+        else
247
+            throw new Ks3ClientException("open file ".$path." error");
248
+    }
249
+    //matdesc为字符串或array数据类型。
250
+    public static function createInstructionFile($bucket,$key,$cek,$iv,$matdesc="{}"){
251
+        if(is_array($matdesc)){
252
+            $matdesc = json_encode($matdesc);
253
+        }
254
+        $key = $key.EncryptionUtil::$INSTRUCTION_SUFFIX;
255 255
 
256
-		$instruction = json_encode(array(
257
-			"x-kss-key"=>$cek,
258
-			"x-kss-iv"=>$iv,
259
-			"x-kss-matdesc"=>$matdesc
260
-			));
256
+        $instruction = json_encode(array(
257
+            "x-kss-key"=>$cek,
258
+            "x-kss-iv"=>$iv,
259
+            "x-kss-matdesc"=>$matdesc
260
+            ));
261 261
 
262
-		$req = array(
263
-			"Bucket"=>$bucket,
264
-			"Key"=>$key,
265
-			"Content"=>$instruction,
266
-			"UserMeta"=>array(
267
-				"x-kss-meta-x-kss-crypto-instr-file"=>base64_encode($key)
268
-				)
269
-			);
270
-		return $req;
271
-	}
272
-	public static function isInstructionFile($s3Object){
273
-		$meta = $s3Object["Meta"];
274
-		if(isset($meta["UserMeta"]["x-kss-meta-x-kss-crypto-instr-file"]))
275
-			return TRUE;
276
-		return FALSE;
277
-	}
262
+        $req = array(
263
+            "Bucket"=>$bucket,
264
+            "Key"=>$key,
265
+            "Content"=>$instruction,
266
+            "UserMeta"=>array(
267
+                "x-kss-meta-x-kss-crypto-instr-file"=>base64_encode($key)
268
+                )
269
+            );
270
+        return $req;
271
+    }
272
+    public static function isInstructionFile($s3Object){
273
+        $meta = $s3Object["Meta"];
274
+        if(isset($meta["UserMeta"]["x-kss-meta-x-kss-crypto-instr-file"]))
275
+            return TRUE;
276
+        return FALSE;
277
+    }
278 278
 }
279 279
 ?>
280 280
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2
-class EncryptionUtil{
2
+class EncryptionUtil {
3 3
 	public static $INSTRUCTION_SUFFIX = ".instruction";
4
-	public static function genereateOnceUsedKey($length=32){
4
+	public static function genereateOnceUsedKey($length = 32) {
5 5
 		$randpwd = "";  
6 6
 		for ($i = 0; $i < $length; $i++)  
7 7
 		{  
@@ -9,24 +9,24 @@  discard block
 block discarded – undo
9 9
 		}  
10 10
 		return $randpwd;   
11 11
 	}
12
-	public static function encode_AES_ECB($data,$secret_key){
13
-		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_ECB,'');
12
+	public static function encode_AES_ECB($data, $secret_key) {
13
+		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
14 14
 
15
-		$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_ECB);
16
-		$pad = $blocksize - (strlen($data) % $blocksize);
17
-		$data = $data . str_repeat(chr($pad), $pad);
15
+		$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
16
+		$pad = $blocksize-(strlen($data)%$blocksize);
17
+		$data = $data.str_repeat(chr($pad), $pad);
18 18
 
19
-		$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
20
-		mcrypt_generic_init($td,$secret_key,$iv);
21
-		$encrypted = mcrypt_generic($td,$data);
19
+		$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
20
+		mcrypt_generic_init($td, $secret_key, $iv);
21
+		$encrypted = mcrypt_generic($td, $data);
22 22
 		mcrypt_generic_deinit($td);
23 23
 		return $encrypted;
24 24
 	}
25
-	public static function decode_AES_ECB($data,$secret_key){
26
-		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_ECB,'');
27
-		$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
28
-		mcrypt_generic_init($td,$secret_key,$iv);
29
-		$data = mdecrypt_generic($td,$data);
25
+	public static function decode_AES_ECB($data, $secret_key) {
26
+		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
27
+		$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
28
+		mcrypt_generic_init($td, $secret_key, $iv);
29
+		$data = mdecrypt_generic($td, $data);
30 30
 		mcrypt_generic_deinit($td);
31 31
 		mcrypt_module_close($td);
32 32
 
@@ -36,155 +36,155 @@  discard block
 block discarded – undo
36 36
 
37 37
 		return trim($data);
38 38
 	}
39
-	public static function getKeyEncryptionAlgm($encryptionMaterials){
40
-		if(is_array($encryptionMaterials)){
39
+	public static function getKeyEncryptionAlgm($encryptionMaterials) {
40
+		if (is_array($encryptionMaterials)) {
41 41
 			return "RSA";
42
-		}else{
42
+		}else {
43 43
 			return "AES";
44 44
 		}
45 45
 	}
46
-	public static function getAdjustedRange($range,$blocksize){
46
+	public static function getAdjustedRange($range, $blocksize) {
47 47
 		$a = $range["start"];
48 48
 		$b = $range["end"];
49
-		$a = $a - ($a%$blocksize)-$blocksize;
50
-		if($a < 0)
49
+		$a = $a-($a%$blocksize)-$blocksize;
50
+		if ($a < 0)
51 51
 			$a = 0;
52 52
 
53 53
 		$b = $b+$blocksize-$b%$blocksize+$blocksize;
54 54
 
55
-		return array("start"=>$a,"end"=>$b);
55
+		return array("start"=>$a, "end"=>$b);
56 56
 	}
57
-	public static function encodeCek($encryptionMaterials,$cek){
57
+	public static function encodeCek($encryptionMaterials, $cek) {
58 58
 		$encrypKeyAlg = EncryptionUtil::getKeyEncryptionAlgm($encryptionMaterials);
59
-		if($encrypKeyAlg === "AES"){
59
+		if ($encrypKeyAlg === "AES") {
60 60
 			$secretKey = $encryptionMaterials;
61
-			$encryptedSek = EncryptionUtil::encode_AES_ECB($cek,$secretKey);
62
-			if(empty($encryptedSek))
61
+			$encryptedSek = EncryptionUtil::encode_AES_ECB($cek, $secretKey);
62
+			if (empty($encryptedSek))
63 63
 				throw new Ks3ClientException("can not encode cek useing AES");
64
-		}else if($encrypKeyAlg === "RSA"){
64
+		}else if ($encrypKeyAlg === "RSA") {
65 65
 			$encryptedSek = "";
66
-			openssl_public_encrypt($cek,$encryptedSek, $encryptionMaterials[0]);
67
-			if(empty($encryptedSek))
66
+			openssl_public_encrypt($cek, $encryptedSek, $encryptionMaterials[0]);
67
+			if (empty($encryptedSek))
68 68
 				throw new Ks3ClientException("can not encode cek useing RSA");
69 69
 		}
70 70
 		return $encryptedSek;
71 71
 	}
72
-	public static function decodeCek($encryptionMaterials,$cekEncrypted){
72
+	public static function decodeCek($encryptionMaterials, $cekEncrypted) {
73 73
 		$encrypKeyAlg = EncryptionUtil::getKeyEncryptionAlgm($encryptionMaterials);
74
-		if($encrypKeyAlg === "AES"){
74
+		if ($encrypKeyAlg === "AES") {
75 75
 			$secretKey = $encryptionMaterials;
76
-			$cek = EncryptionUtil::decode_AES_ECB($cekEncrypted,$secretKey);
77
-			if(empty($cek))
76
+			$cek = EncryptionUtil::decode_AES_ECB($cekEncrypted, $secretKey);
77
+			if (empty($cek))
78 78
 				throw new Ks3ClientException("can not decode cek useing AES,secret key maybe not correct");
79
-		}else if($encrypKeyAlg === "RSA"){
79
+		}else if ($encrypKeyAlg === "RSA") {
80 80
 			$cek = "";
81
-			openssl_private_decrypt($cekEncrypted,$cek, $encryptionMaterials[1]);
82
-			if(empty($cek))
81
+			openssl_private_decrypt($cekEncrypted, $cek, $encryptionMaterials[1]);
82
+			if (empty($cek))
83 83
 				throw new Ks3ClientException("can not decode cek useing RSA,public/private key pair maybe not correct");
84 84
 		}
85 85
 		return $cek;
86 86
 	}
87
-	public static function getPKCS5EncrypedLength($length,$blocksize){
88
-		$pad = $blocksize - $length%$blocksize;
87
+	public static function getPKCS5EncrypedLength($length, $blocksize) {
88
+		$pad = $blocksize-$length%$blocksize;
89 89
 		return $length+$pad;
90 90
 	}
91 91
 	//pkcs5填充
92
-	public static function PKCS5Padding($data,$blocksize){
93
-		$pad = $blocksize - strlen($data)%$blocksize;
94
-		for($i = 0;$i < $pad;$i++){
95
-			$data.= chr($pad);
92
+	public static function PKCS5Padding($data, $blocksize) {
93
+		$pad = $blocksize-strlen($data)%$blocksize;
94
+		for ($i = 0; $i < $pad; $i++) {
95
+			$data .= chr($pad);
96 96
 		}
97 97
 		return $data;
98 98
 	}
99
-	public static function updateContentMD5Header($req){
100
-		if(!is_array($req))
99
+	public static function updateContentMD5Header($req) {
100
+		if (!is_array($req))
101 101
 			return $req;
102
-		if(isset($req["ObjectMeta"])){
102
+		if (isset($req["ObjectMeta"])) {
103 103
 			$meta = $req["ObjectMeta"];
104
-		}else{
104
+		}else {
105 105
 			return $req;
106 106
 		}
107
-		if(is_array($meta) && isset($meta["Content-MD5"])){
107
+		if (is_array($meta) && isset($meta["Content-MD5"])) {
108 108
 			$md5 = $meta["Content-MD5"];
109
-		}else{
109
+		}else {
110 110
 			return $req;
111 111
 		}
112
-		if(empty($md5)){
112
+		if (empty($md5)) {
113 113
 			return $req;
114
-		}else{
114
+		}else {
115 115
 			$req["ObjectMeta"]["Content-MD5"] = NULL;
116 116
 			$req["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-md5"] = $md5;
117 117
 		}
118 118
 		return $req;
119 119
 	}
120
-	public static function metaTextLength($req){
121
-		if(!is_array($req))
120
+	public static function metaTextLength($req) {
121
+		if (!is_array($req))
122 122
 			return -1;
123
-		if(isset($req["ObjectMeta"])){
123
+		if (isset($req["ObjectMeta"])) {
124 124
 			$meta = $req["ObjectMeta"];
125
-		}else{
125
+		}else {
126 126
 			return -1;
127 127
 		}
128
-		if(is_array($meta) && isset($meta["Content-Length"])){
128
+		if (is_array($meta) && isset($meta["Content-Length"])) {
129 129
 			$length = $meta["Content-Length"];
130 130
 			return $length;
131 131
 		}else
132 132
 			return -1;
133 133
 	}
134
-	public static function plainTextLength($args){
135
-		if(isset($args["Content"])){
136
-			if(is_array($args["Content"])){
134
+	public static function plainTextLength($args) {
135
+		if (isset($args["Content"])) {
136
+			if (is_array($args["Content"])) {
137 137
 				$content = $args["Content"]["content"];
138 138
 				$seek_position = 0;
139 139
 				$resourceLength = 0;
140 140
 				$length = -1;
141 141
 				$isFile = FALSE;
142 142
 
143
-				if (!is_resource($content)){
143
+				if (!is_resource($content)) {
144 144
 					$isFile = TRUE;
145 145
 					//如果之前用户已经转化为GBK则不转换
146
-					if(Utils::chk_chinese($content)&&!Utils::check_char($content)){
147
-						$content = iconv('utf-8','gbk',$content);
146
+					if (Utils::chk_chinese($content) && !Utils::check_char($content)) {
147
+						$content = iconv('utf-8', 'gbk', $content);
148 148
 					}
149
-					if(!file_exists($content))
149
+					if (!file_exists($content))
150 150
 						throw new Ks3ClientException("the specified file does not exist ");
151 151
 					$length = Utils::getFileSize($content);
152
-					$content = fopen($content,"r");
153
-				}else{
152
+					$content = fopen($content, "r");
153
+				}else {
154 154
 					$stats = fstat($content);
155
-					if ($stats && $stats["size"] >= 0){
155
+					if ($stats && $stats["size"] >= 0) {
156 156
 						$length = $stats["size"];	
157 157
 					}
158 158
 				}
159 159
 				$resourceLength = $length;
160 160
 				//优先取用户设置seek_position,没有的话取ftell
161
-				if(isset($args["Content"]["seek_position"])&&$args["Content"]["seek_position"]>0){
161
+				if (isset($args["Content"]["seek_position"]) && $args["Content"]["seek_position"] > 0) {
162 162
 					$seek_position = $args["Content"]["seek_position"];
163
-				}else if(!$isFile){
163
+				}else if (!$isFile) {
164 164
 					$seek_position = ftell($content);
165
-					if($seek_position<0)
165
+					if ($seek_position < 0)
166 166
 						$seek_position = 0;
167
-					fseek($content,0);
167
+					fseek($content, 0);
168 168
 				}
169 169
 
170 170
 				$lengthInMeta = -1;
171
-				if(isset($args["ObjectMeta"]["Content-Length"])){
171
+				if (isset($args["ObjectMeta"]["Content-Length"])) {
172 172
 					$lengthInMeta = $args["ObjectMeta"]["Content-Length"];
173 173
 				}
174
-				if($lengthInMeta > 0){
174
+				if ($lengthInMeta > 0) {
175 175
 					$length = $lengthInMeta;
176
-				}else if($resourceLength > 0){
176
+				}else if ($resourceLength > 0) {
177 177
 					//根据seek_position计算实际长度
178
-					$length = $resourceLength - $seek_position;
178
+					$length = $resourceLength-$seek_position;
179 179
 				}
180
-				if($length <= 0)
180
+				if ($length <= 0)
181 181
 					throw new Ks3ClientException("calculate content length failed,unexpected contetn length ".$length);
182 182
 				return $length;
183
-			}else{
183
+			}else {
184 184
 				$content = $args["Content"];
185 185
 				$lengthInMeta = EncryptionUtil::metaTextLength($args);
186 186
 				$length = strlen($content);
187
-				if($length<$lengthInMeta||$lengthInMeta <= 0)
187
+				if ($length < $lengthInMeta || $lengthInMeta <= 0)
188 188
 					return $length;
189 189
 				else
190 190
 					return $lengthInMeta;
@@ -192,14 +192,14 @@  discard block
 block discarded – undo
192 192
 		}
193 193
 		return -1;
194 194
 	}
195
-	public static function initMultipartUploadContext($initResult,$iv,$cek,$encryptedCek,$matdesc="{}"){
195
+	public static function initMultipartUploadContext($initResult, $iv, $cek, $encryptedCek, $matdesc = "{}") {
196 196
 		$cacheDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR;
197 197
 		$encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
198
-		if(!is_dir($cacheDir))
198
+		if (!is_dir($cacheDir))
199 199
 			mkdir($cacheDir);
200
-		if(!is_dir($encryptionDir))
200
+		if (!is_dir($encryptionDir))
201 201
 			mkdir($encryptionDir);
202
-		if(is_array($matdesc)){
202
+		if (is_array($matdesc)) {
203 203
 			$matdesc = json_encode($matdesc);
204 204
 		}
205 205
 		$initResult["firstIv"] = base64_encode($iv);
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 		fwrite($file, $json);
214 214
 		fclose($file);
215 215
 	}
216
-	public static function updateMultipartUploadContext($UploadId,$iv,$lastPart = FALSE){
216
+	public static function updateMultipartUploadContext($UploadId, $iv, $lastPart = FALSE) {
217 217
 		$encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
218 218
 		$content = EncryptionUtil::getMultipartUploadContext($UploadId);
219 219
 		$content["nextIv"] = base64_encode($iv);
@@ -223,32 +223,32 @@  discard block
 block discarded – undo
223 223
 		fwrite($file, $json);
224 224
 		fclose($file);
225 225
 	}
226
-	public static function getMultipartUploadContext($UploadId){
226
+	public static function getMultipartUploadContext($UploadId) {
227 227
 		$encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
228
-		if(!EncryptionUtil::multipartUploadContextExists($UploadId))
228
+		if (!EncryptionUtil::multipartUploadContextExists($UploadId))
229 229
 			throw new Ks3ClientException("can not found multipart upload context in cache dir");
230 230
 		$jsonString = file_get_contents($encryptionDir.$UploadId);
231
-		$arry = json_decode($jsonString,TRUE);
231
+		$arry = json_decode($jsonString, TRUE);
232 232
 		return $arry;
233 233
 	}
234
-	public static function deleteMultipartUploadContext($UploadId){
234
+	public static function deleteMultipartUploadContext($UploadId) {
235 235
 		$encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
236 236
 		@unlink($encryptionDir.$UploadId);
237 237
 	}
238
-	public static function multipartUploadContextExists($UploadId){
238
+	public static function multipartUploadContextExists($UploadId) {
239 239
 		$encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
240 240
 		return file_exists($encryptionDir.$UploadId);
241 241
 	}
242
-	public static function openfile($path,$mode){
242
+	public static function openfile($path, $mode) {
243 243
 		$file = fopen($path, $mode);
244
-		if($file)
244
+		if ($file)
245 245
 			return $file;
246 246
 		else
247 247
 			throw new Ks3ClientException("open file ".$path." error");
248 248
 	}
249 249
 	//matdesc为字符串或array数据类型。
250
-	public static function createInstructionFile($bucket,$key,$cek,$iv,$matdesc="{}"){
251
-		if(is_array($matdesc)){
250
+	public static function createInstructionFile($bucket, $key, $cek, $iv, $matdesc = "{}") {
251
+		if (is_array($matdesc)) {
252 252
 			$matdesc = json_encode($matdesc);
253 253
 		}
254 254
 		$key = $key.EncryptionUtil::$INSTRUCTION_SUFFIX;
@@ -269,9 +269,9 @@  discard block
 block discarded – undo
269 269
 			);
270 270
 		return $req;
271 271
 	}
272
-	public static function isInstructionFile($s3Object){
272
+	public static function isInstructionFile($s3Object) {
273 273
 		$meta = $s3Object["Meta"];
274
-		if(isset($meta["UserMeta"]["x-kss-meta-x-kss-crypto-instr-file"]))
274
+		if (isset($meta["UserMeta"]["x-kss-meta-x-kss-crypto-instr-file"]))
275 275
 			return TRUE;
276 276
 		return FALSE;
277 277
 	}
Please login to merge, or discard this patch.
Braces   +66 added lines, -49 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	public static function getKeyEncryptionAlgm($encryptionMaterials){
40 40
 		if(is_array($encryptionMaterials)){
41 41
 			return "RSA";
42
-		}else{
42
+		} else{
43 43
 			return "AES";
44 44
 		}
45 45
 	}
@@ -47,8 +47,9 @@  discard block
 block discarded – undo
47 47
 		$a = $range["start"];
48 48
 		$b = $range["end"];
49 49
 		$a = $a - ($a%$blocksize)-$blocksize;
50
-		if($a < 0)
51
-			$a = 0;
50
+		if($a < 0) {
51
+					$a = 0;
52
+		}
52 53
 
53 54
 		$b = $b+$blocksize-$b%$blocksize+$blocksize;
54 55
 
@@ -59,13 +60,15 @@  discard block
 block discarded – undo
59 60
 		if($encrypKeyAlg === "AES"){
60 61
 			$secretKey = $encryptionMaterials;
61 62
 			$encryptedSek = EncryptionUtil::encode_AES_ECB($cek,$secretKey);
62
-			if(empty($encryptedSek))
63
-				throw new Ks3ClientException("can not encode cek useing AES");
64
-		}else if($encrypKeyAlg === "RSA"){
63
+			if(empty($encryptedSek)) {
64
+							throw new Ks3ClientException("can not encode cek useing AES");
65
+			}
66
+		} else if($encrypKeyAlg === "RSA"){
65 67
 			$encryptedSek = "";
66 68
 			openssl_public_encrypt($cek,$encryptedSek, $encryptionMaterials[0]);
67
-			if(empty($encryptedSek))
68
-				throw new Ks3ClientException("can not encode cek useing RSA");
69
+			if(empty($encryptedSek)) {
70
+							throw new Ks3ClientException("can not encode cek useing RSA");
71
+			}
69 72
 		}
70 73
 		return $encryptedSek;
71 74
 	}
@@ -74,13 +77,15 @@  discard block
 block discarded – undo
74 77
 		if($encrypKeyAlg === "AES"){
75 78
 			$secretKey = $encryptionMaterials;
76 79
 			$cek = EncryptionUtil::decode_AES_ECB($cekEncrypted,$secretKey);
77
-			if(empty($cek))
78
-				throw new Ks3ClientException("can not decode cek useing AES,secret key maybe not correct");
79
-		}else if($encrypKeyAlg === "RSA"){
80
+			if(empty($cek)) {
81
+							throw new Ks3ClientException("can not decode cek useing AES,secret key maybe not correct");
82
+			}
83
+		} else if($encrypKeyAlg === "RSA"){
80 84
 			$cek = "";
81 85
 			openssl_private_decrypt($cekEncrypted,$cek, $encryptionMaterials[1]);
82
-			if(empty($cek))
83
-				throw new Ks3ClientException("can not decode cek useing RSA,public/private key pair maybe not correct");
86
+			if(empty($cek)) {
87
+							throw new Ks3ClientException("can not decode cek useing RSA,public/private key pair maybe not correct");
88
+			}
84 89
 		}
85 90
 		return $cek;
86 91
 	}
@@ -97,39 +102,42 @@  discard block
 block discarded – undo
97 102
 		return $data;
98 103
 	}
99 104
 	public static function updateContentMD5Header($req){
100
-		if(!is_array($req))
101
-			return $req;
105
+		if(!is_array($req)) {
106
+					return $req;
107
+		}
102 108
 		if(isset($req["ObjectMeta"])){
103 109
 			$meta = $req["ObjectMeta"];
104
-		}else{
110
+		} else{
105 111
 			return $req;
106 112
 		}
107 113
 		if(is_array($meta) && isset($meta["Content-MD5"])){
108 114
 			$md5 = $meta["Content-MD5"];
109
-		}else{
115
+		} else{
110 116
 			return $req;
111 117
 		}
112 118
 		if(empty($md5)){
113 119
 			return $req;
114
-		}else{
120
+		} else{
115 121
 			$req["ObjectMeta"]["Content-MD5"] = NULL;
116 122
 			$req["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-md5"] = $md5;
117 123
 		}
118 124
 		return $req;
119 125
 	}
120 126
 	public static function metaTextLength($req){
121
-		if(!is_array($req))
122
-			return -1;
127
+		if(!is_array($req)) {
128
+					return -1;
129
+		}
123 130
 		if(isset($req["ObjectMeta"])){
124 131
 			$meta = $req["ObjectMeta"];
125
-		}else{
132
+		} else{
126 133
 			return -1;
127 134
 		}
128 135
 		if(is_array($meta) && isset($meta["Content-Length"])){
129 136
 			$length = $meta["Content-Length"];
130 137
 			return $length;
131
-		}else
132
-			return -1;
138
+		} else {
139
+					return -1;
140
+		}
133 141
 	}
134 142
 	public static function plainTextLength($args){
135 143
 		if(isset($args["Content"])){
@@ -146,11 +154,12 @@  discard block
 block discarded – undo
146 154
 					if(Utils::chk_chinese($content)&&!Utils::check_char($content)){
147 155
 						$content = iconv('utf-8','gbk',$content);
148 156
 					}
149
-					if(!file_exists($content))
150
-						throw new Ks3ClientException("the specified file does not exist ");
157
+					if(!file_exists($content)) {
158
+											throw new Ks3ClientException("the specified file does not exist ");
159
+					}
151 160
 					$length = Utils::getFileSize($content);
152 161
 					$content = fopen($content,"r");
153
-				}else{
162
+				} else{
154 163
 					$stats = fstat($content);
155 164
 					if ($stats && $stats["size"] >= 0){
156 165
 						$length = $stats["size"];	
@@ -160,10 +169,11 @@  discard block
 block discarded – undo
160 169
 				//优先取用户设置seek_position,没有的话取ftell
161 170
 				if(isset($args["Content"]["seek_position"])&&$args["Content"]["seek_position"]>0){
162 171
 					$seek_position = $args["Content"]["seek_position"];
163
-				}else if(!$isFile){
172
+				} else if(!$isFile){
164 173
 					$seek_position = ftell($content);
165
-					if($seek_position<0)
166
-						$seek_position = 0;
174
+					if($seek_position<0) {
175
+											$seek_position = 0;
176
+					}
167 177
 					fseek($content,0);
168 178
 				}
169 179
 
@@ -173,21 +183,23 @@  discard block
 block discarded – undo
173 183
 				}
174 184
 				if($lengthInMeta > 0){
175 185
 					$length = $lengthInMeta;
176
-				}else if($resourceLength > 0){
186
+				} else if($resourceLength > 0){
177 187
 					//根据seek_position计算实际长度
178 188
 					$length = $resourceLength - $seek_position;
179 189
 				}
180
-				if($length <= 0)
181
-					throw new Ks3ClientException("calculate content length failed,unexpected contetn length ".$length);
190
+				if($length <= 0) {
191
+									throw new Ks3ClientException("calculate content length failed,unexpected contetn length ".$length);
192
+				}
182 193
 				return $length;
183
-			}else{
194
+			} else{
184 195
 				$content = $args["Content"];
185 196
 				$lengthInMeta = EncryptionUtil::metaTextLength($args);
186 197
 				$length = strlen($content);
187
-				if($length<$lengthInMeta||$lengthInMeta <= 0)
188
-					return $length;
189
-				else
190
-					return $lengthInMeta;
198
+				if($length<$lengthInMeta||$lengthInMeta <= 0) {
199
+									return $length;
200
+				} else {
201
+									return $lengthInMeta;
202
+				}
191 203
 			}
192 204
 		}
193 205
 		return -1;
@@ -195,10 +207,12 @@  discard block
 block discarded – undo
195 207
 	public static function initMultipartUploadContext($initResult,$iv,$cek,$encryptedCek,$matdesc="{}"){
196 208
 		$cacheDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR;
197 209
 		$encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
198
-		if(!is_dir($cacheDir))
199
-			mkdir($cacheDir);
200
-		if(!is_dir($encryptionDir))
201
-			mkdir($encryptionDir);
210
+		if(!is_dir($cacheDir)) {
211
+					mkdir($cacheDir);
212
+		}
213
+		if(!is_dir($encryptionDir)) {
214
+					mkdir($encryptionDir);
215
+		}
202 216
 		if(is_array($matdesc)){
203 217
 			$matdesc = json_encode($matdesc);
204 218
 		}
@@ -225,8 +239,9 @@  discard block
 block discarded – undo
225 239
 	}
226 240
 	public static function getMultipartUploadContext($UploadId){
227 241
 		$encryptionDir = KS3_API_PATH.DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR;
228
-		if(!EncryptionUtil::multipartUploadContextExists($UploadId))
229
-			throw new Ks3ClientException("can not found multipart upload context in cache dir");
242
+		if(!EncryptionUtil::multipartUploadContextExists($UploadId)) {
243
+					throw new Ks3ClientException("can not found multipart upload context in cache dir");
244
+		}
230 245
 		$jsonString = file_get_contents($encryptionDir.$UploadId);
231 246
 		$arry = json_decode($jsonString,TRUE);
232 247
 		return $arry;
@@ -241,10 +256,11 @@  discard block
 block discarded – undo
241 256
 	}
242 257
 	public static function openfile($path,$mode){
243 258
 		$file = fopen($path, $mode);
244
-		if($file)
245
-			return $file;
246
-		else
247
-			throw new Ks3ClientException("open file ".$path." error");
259
+		if($file) {
260
+					return $file;
261
+		} else {
262
+					throw new Ks3ClientException("open file ".$path." error");
263
+		}
248 264
 	}
249 265
 	//matdesc为字符串或array数据类型。
250 266
 	public static function createInstructionFile($bucket,$key,$cek,$iv,$matdesc="{}"){
@@ -271,8 +287,9 @@  discard block
 block discarded – undo
271 287
 	}
272 288
 	public static function isInstructionFile($s3Object){
273 289
 		$meta = $s3Object["Meta"];
274
-		if(isset($meta["UserMeta"]["x-kss-meta-x-kss-crypto-instr-file"]))
275
-			return TRUE;
290
+		if(isset($meta["UserMeta"]["x-kss-meta-x-kss-crypto-instr-file"])) {
291
+					return TRUE;
292
+		}
276 293
 		return FALSE;
277 294
 	}
278 295
 }
Please login to merge, or discard this patch.
src/service/ksyun/bin/encryption/EncryptionHandlers.php 3 patches
Indentation   +322 added lines, -322 removed lines patch added patch discarded remove patch
@@ -3,356 +3,356 @@
 block discarded – undo
3 3
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR."EncryptionCallBack.php";
4 4
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php";
5 5
 interface EncryptionHandler{
6
-	public function putObjectByContentSecurely($args=array());
7
-	public function putObjectByFileSecurely($args=array());
8
-	public function getObjectSecurely($args=array());
9
-	public function initMultipartUploadSecurely($args=array());
10
-	public function uploadPartSecurely($args=array());
11
-	public function abortMultipartUploadSecurely($args=array());
12
-	public function completeMultipartUploadSecurely($args=array());
6
+    public function putObjectByContentSecurely($args=array());
7
+    public function putObjectByFileSecurely($args=array());
8
+    public function getObjectSecurely($args=array());
9
+    public function initMultipartUploadSecurely($args=array());
10
+    public function uploadPartSecurely($args=array());
11
+    public function abortMultipartUploadSecurely($args=array());
12
+    public function completeMultipartUploadSecurely($args=array());
13 13
 }
14 14
 class EncryptionEO implements EncryptionHandler{
15
-	private $encryptionMaterials = NULL;
16
-	private $ks3client = NULL;
17
-	public function __construct($ks3client,$encryptionMaterials){
18
-		$this->encryptionMaterials = $encryptionMaterials;
19
-		$this->ks3client = $ks3client;
20
-	}
21
-	public function putObjectByContentSecurely($args=array()){
22
-		$sek = EncryptionUtil::genereateOnceUsedKey();
23
-		$encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials,$sek);
24
-		$content = $args["Content"];
25
-		if(empty($content))
26
-			throw new Ks3ClientException("please specifie Content in request args");
27
-		$metaContentLength = EncryptionUtil::metaTextLength($args);
28
-		$plainTextLength = strlen($content);
29
-		if($metaContentLength > 0 && $metaContentLength < $plainTextLength){
30
-			$plainTextLength = $metaContentLength;
31
-		}
32
-		if($plainTextLength > 0)
33
-			$args["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-length"] = $plainTextLength;
34
-		else
35
-			throw new Ks3ClientException("unexpected content length ".$plainTextLength);
15
+    private $encryptionMaterials = NULL;
16
+    private $ks3client = NULL;
17
+    public function __construct($ks3client,$encryptionMaterials){
18
+        $this->encryptionMaterials = $encryptionMaterials;
19
+        $this->ks3client = $ks3client;
20
+    }
21
+    public function putObjectByContentSecurely($args=array()){
22
+        $sek = EncryptionUtil::genereateOnceUsedKey();
23
+        $encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials,$sek);
24
+        $content = $args["Content"];
25
+        if(empty($content))
26
+            throw new Ks3ClientException("please specifie Content in request args");
27
+        $metaContentLength = EncryptionUtil::metaTextLength($args);
28
+        $plainTextLength = strlen($content);
29
+        if($metaContentLength > 0 && $metaContentLength < $plainTextLength){
30
+            $plainTextLength = $metaContentLength;
31
+        }
32
+        if($plainTextLength > 0)
33
+            $args["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-length"] = $plainTextLength;
34
+        else
35
+            throw new Ks3ClientException("unexpected content length ".$plainTextLength);
36 36
 
37
-		$content =  substr($content, 0,$plainTextLength);
37
+        $content =  substr($content, 0,$plainTextLength);
38 38
 
39 39
 
40
-		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
41
-		$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_RAND);
42
-		mcrypt_generic_init($td,$sek,$iv);
43
-		//对content进行pkcs5填充
44
-		$content = EncryptionUtil::PKCS5Padding($content,mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC));
45
-		$encrypted = mcrypt_generic($td,$content);
46
-		mcrypt_generic_deinit($td);
40
+        $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
41
+        $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_RAND);
42
+        mcrypt_generic_init($td,$sek,$iv);
43
+        //对content进行pkcs5填充
44
+        $content = EncryptionUtil::PKCS5Padding($content,mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC));
45
+        $encrypted = mcrypt_generic($td,$content);
46
+        mcrypt_generic_deinit($td);
47 47
 
48
-		$args["ObjectMeta"]["Content-Length"] = strlen($encrypted);
49
-		$args["Content"] = $encrypted; 
48
+        $args["ObjectMeta"]["Content-Length"] = strlen($encrypted);
49
+        $args["Content"] = $encrypted; 
50 50
 
51
-		$args = EncryptionUtil::updateContentMD5Header($args);
51
+        $args = EncryptionUtil::updateContentMD5Header($args);
52 52
 
53
-		//TODO
54
-		$matdesc = "{}";
55
-		if(ENCRYPTPTION_STORAGE_MODE == "ObjectMetadata"){
56
-			$args["UserMeta"]["x-kss-meta-x-kss-key"] = base64_encode($encryptedSek);
57
-			$args["UserMeta"]["x-kss-meta-x-kss-iv"] = base64_encode($iv);
58
-			$args["UserMeta"]["x-kss-meta-x-kss-matdesc"] = $matdesc;
59
-		}
53
+        //TODO
54
+        $matdesc = "{}";
55
+        if(ENCRYPTPTION_STORAGE_MODE == "ObjectMetadata"){
56
+            $args["UserMeta"]["x-kss-meta-x-kss-key"] = base64_encode($encryptedSek);
57
+            $args["UserMeta"]["x-kss-meta-x-kss-iv"] = base64_encode($iv);
58
+            $args["UserMeta"]["x-kss-meta-x-kss-matdesc"] = $matdesc;
59
+        }
60 60
 
61
-		$result = $this->ks3client->putObjectByContent($args);
61
+        $result = $this->ks3client->putObjectByContent($args);
62 62
 
63
-		if(ENCRYPTPTION_STORAGE_MODE == "InstructionFile"){
64
-			$req = EncryptionUtil::createInstructionFile($args["Bucket"],$args["Key"],
65
-			base64_encode($encryptedSek),base64_encode($iv),$matdesc);
66
-			$this->ks3client->putObjectByContent($req);
67
-		}
63
+        if(ENCRYPTPTION_STORAGE_MODE == "InstructionFile"){
64
+            $req = EncryptionUtil::createInstructionFile($args["Bucket"],$args["Key"],
65
+            base64_encode($encryptedSek),base64_encode($iv),$matdesc);
66
+            $this->ks3client->putObjectByContent($req);
67
+        }
68 68
 
69
-		return $result;
70
-	}
71
-	public function putObjectByFileSecurely($args=array()){
72
-		$sek = EncryptionUtil::genereateOnceUsedKey();
73
-		$encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials,$sek);
74
-		if(!isset($args["Content"])||!is_array($args["Content"])
75
-			||!isset($args["Content"]["content"])
76
-			||empty($args["Content"]["content"]))
77
-			throw new Ks3ClientException("please specifie file content in request args");
78
-		$content = $args["Content"];
79
-		$plainTextLength = EncryptionUtil::plainTextLength($args);
80
-		if($plainTextLength <= 0){
81
-			throw new Ks3ClientException("get content length failed ,unexpected content length ".$plainTextLength);
82
-		}
83
-		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
84
-		$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_RAND);
69
+        return $result;
70
+    }
71
+    public function putObjectByFileSecurely($args=array()){
72
+        $sek = EncryptionUtil::genereateOnceUsedKey();
73
+        $encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials,$sek);
74
+        if(!isset($args["Content"])||!is_array($args["Content"])
75
+            ||!isset($args["Content"]["content"])
76
+            ||empty($args["Content"]["content"]))
77
+            throw new Ks3ClientException("please specifie file content in request args");
78
+        $content = $args["Content"];
79
+        $plainTextLength = EncryptionUtil::plainTextLength($args);
80
+        if($plainTextLength <= 0){
81
+            throw new Ks3ClientException("get content length failed ,unexpected content length ".$plainTextLength);
82
+        }
83
+        $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
84
+        $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_RAND);
85 85
 
86
-		$args = EncryptionUtil::updateContentMD5Header($args);
87
-		$encryptedLength = EncryptionUtil::getPKCS5EncrypedLength($plainTextLength,mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC));
86
+        $args = EncryptionUtil::updateContentMD5Header($args);
87
+        $encryptedLength = EncryptionUtil::getPKCS5EncrypedLength($plainTextLength,mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC));
88 88
 
89
-		$args["ObjectMeta"]["Content-Length"] = $encryptedLength;
90
-		$args["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-length"] = $plainTextLength;
89
+        $args["ObjectMeta"]["Content-Length"] = $encryptedLength;
90
+        $args["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-length"] = $plainTextLength;
91 91
 
92
-		$readCallBack = new AESCBCStreamReadCallBack();
93
-		$readCallBack->iv = $iv;
94
-		$readCallBack->cek = $sek;
95
-		$readCallBack->contentLength = $plainTextLength;
96
-		$args["readCallBack"] = $readCallBack;
92
+        $readCallBack = new AESCBCStreamReadCallBack();
93
+        $readCallBack->iv = $iv;
94
+        $readCallBack->cek = $sek;
95
+        $readCallBack->contentLength = $plainTextLength;
96
+        $args["readCallBack"] = $readCallBack;
97 97
 
98
-		//TODO
99
-		$matdesc = "{}";
100
-		if(ENCRYPTPTION_STORAGE_MODE == "ObjectMetadata"){
101
-			$args["UserMeta"]["x-kss-meta-x-kss-key"] = base64_encode($encryptedSek);
102
-			$args["UserMeta"]["x-kss-meta-x-kss-iv"] = base64_encode($iv);
103
-			$args["UserMeta"]["x-kss-meta-x-kss-matdesc"] = $matdesc;
104
-		}
98
+        //TODO
99
+        $matdesc = "{}";
100
+        if(ENCRYPTPTION_STORAGE_MODE == "ObjectMetadata"){
101
+            $args["UserMeta"]["x-kss-meta-x-kss-key"] = base64_encode($encryptedSek);
102
+            $args["UserMeta"]["x-kss-meta-x-kss-iv"] = base64_encode($iv);
103
+            $args["UserMeta"]["x-kss-meta-x-kss-matdesc"] = $matdesc;
104
+        }
105 105
 
106
-		$result = $this->ks3client->putObjectByFile($args);
106
+        $result = $this->ks3client->putObjectByFile($args);
107 107
 
108
-		if(ENCRYPTPTION_STORAGE_MODE == "InstructionFile"){
109
-			$req = EncryptionUtil::createInstructionFile($args["Bucket"],$args["Key"],
110
-			base64_encode($encryptedSek),base64_encode($iv),$matdesc);
111
-			$this->ks3client->putObjectByContent($req);
112
-		}
108
+        if(ENCRYPTPTION_STORAGE_MODE == "InstructionFile"){
109
+            $req = EncryptionUtil::createInstructionFile($args["Bucket"],$args["Key"],
110
+            base64_encode($encryptedSek),base64_encode($iv),$matdesc);
111
+            $this->ks3client->putObjectByContent($req);
112
+        }
113 113
 
114
-		return $result;
115
-	}
116
-	public function getObjectSecurely($args=array()){
117
-		$meta = $this->ks3client->getObjectMeta($args);
118
-		if(isset($meta["UserMeta"]["x-kss-meta-x-kss-key"])&&isset($meta["UserMeta"]["x-kss-meta-x-kss-iv"])){
119
-			$encryptedInMeta = TRUE;
120
-		}else{
121
-			$encryptedInMeta = FALSE;
122
-		}
123
-		$encrypted = TRUE;
124
-		$encryptionInfo = array();
125
-		if($encryptedInMeta){
126
-			$encryptionInfo["iv"] = base64_decode($meta["UserMeta"]["x-kss-meta-x-kss-iv"]);
127
-			$matdesc =$meta["UserMeta"]["x-kss-meta-x-kss-matdesc"];
128
-			$encryptionInfo["matdesc"] = $matdesc;
129
-			$cekEncrypted = base64_decode($meta["UserMeta"]["x-kss-meta-x-kss-key"]);
130
-			$encryptionInfo["cek"] = $cek = EncryptionUtil::decodeCek($this->encryptionMaterials,$cekEncrypted);
131
-		}else{
132
-			if($this->ks3client->objectExists(array(
133
-				"Bucket"=>$args["Bucket"],
134
-				"Key"=>$args["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX)
135
-				)
136
-			){
137
-				$insKey = $args["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX;
138
-				$getIns = array(
139
-					"Bucket"=>$args["Bucket"],
140
-					"Key"=>$insKey,
141
-				);
142
-				$s3Object = $this->ks3client->getObject($getIns);
143
-				if(!EncryptionUtil::isInstructionFile($s3Object))
144
-					throw new Ks3ClientException($insKey." is not an InstructionFile");
114
+        return $result;
115
+    }
116
+    public function getObjectSecurely($args=array()){
117
+        $meta = $this->ks3client->getObjectMeta($args);
118
+        if(isset($meta["UserMeta"]["x-kss-meta-x-kss-key"])&&isset($meta["UserMeta"]["x-kss-meta-x-kss-iv"])){
119
+            $encryptedInMeta = TRUE;
120
+        }else{
121
+            $encryptedInMeta = FALSE;
122
+        }
123
+        $encrypted = TRUE;
124
+        $encryptionInfo = array();
125
+        if($encryptedInMeta){
126
+            $encryptionInfo["iv"] = base64_decode($meta["UserMeta"]["x-kss-meta-x-kss-iv"]);
127
+            $matdesc =$meta["UserMeta"]["x-kss-meta-x-kss-matdesc"];
128
+            $encryptionInfo["matdesc"] = $matdesc;
129
+            $cekEncrypted = base64_decode($meta["UserMeta"]["x-kss-meta-x-kss-key"]);
130
+            $encryptionInfo["cek"] = $cek = EncryptionUtil::decodeCek($this->encryptionMaterials,$cekEncrypted);
131
+        }else{
132
+            if($this->ks3client->objectExists(array(
133
+                "Bucket"=>$args["Bucket"],
134
+                "Key"=>$args["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX)
135
+                )
136
+            ){
137
+                $insKey = $args["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX;
138
+                $getIns = array(
139
+                    "Bucket"=>$args["Bucket"],
140
+                    "Key"=>$insKey,
141
+                );
142
+                $s3Object = $this->ks3client->getObject($getIns);
143
+                if(!EncryptionUtil::isInstructionFile($s3Object))
144
+                    throw new Ks3ClientException($insKey." is not an InstructionFile");
145 145
 
146
-				$content = $s3Object["Content"];
147
-				$content = json_decode($content,TRUE);
148
-				$encryptionInfo["iv"] = base64_decode($content["x-kss-iv"]);
149
-				$matdesc =$content["x-kss-matdesc"];
150
-				$encryptionInfo["matdesc"] = $matdesc;
151
-				$cekEncrypted = base64_decode($content["x-kss-key"]);
152
-				$encryptionInfo["cek"] = $cek = EncryptionUtil::decodeCek($this->encryptionMaterials,$cekEncrypted);
153
-			}else{
154
-				$encrypted =FALSE;
155
-			}
156
-		}
157
-		//是否为下载到文件中
158
-		$isWriteToFile=FALSE;
159
-		if($encrypted)
160
-		{
161
-			$iv = $encryptionInfo["iv"];
162
-			$cek = $encryptionInfo["cek"];
146
+                $content = $s3Object["Content"];
147
+                $content = json_decode($content,TRUE);
148
+                $encryptionInfo["iv"] = base64_decode($content["x-kss-iv"]);
149
+                $matdesc =$content["x-kss-matdesc"];
150
+                $encryptionInfo["matdesc"] = $matdesc;
151
+                $cekEncrypted = base64_decode($content["x-kss-key"]);
152
+                $encryptionInfo["cek"] = $cek = EncryptionUtil::decodeCek($this->encryptionMaterials,$cekEncrypted);
153
+            }else{
154
+                $encrypted =FALSE;
155
+            }
156
+        }
157
+        //是否为下载到文件中
158
+        $isWriteToFile=FALSE;
159
+        if($encrypted)
160
+        {
161
+            $iv = $encryptionInfo["iv"];
162
+            $cek = $encryptionInfo["cek"];
163 163
 
164
-			if(empty($iv))
165
-				throw new Ks3ClientException("can not find iv in UserMeta or InstructionFile");
166
-			if(empty($cek))
167
-				throw new Ks3ClientException("can not find cek in UserMeta or InstructionFile");
164
+            if(empty($iv))
165
+                throw new Ks3ClientException("can not find iv in UserMeta or InstructionFile");
166
+            if(empty($cek))
167
+                throw new Ks3ClientException("can not find cek in UserMeta or InstructionFile");
168 168
 
169
-			if(isset($args["Range"])){
170
-				$range = $args["Range"];
171
-				if(!is_array($range)){
172
-					if(preg_match('/^bytes=[0-9]*-[0-9]*$/', $range)){
173
-						$ranges = explode("-",substr($range,strlen("bytes=")));
174
-						$a = $ranges[0];
175
-						$b = $ranges[1];
176
-						if($a > $b){
177
-							throw new Ks3ClientException("Invalid range ".$range);
178
-						}
179
-						$range = array("start"=>$a,"end"=>$b);
180
-					}else{
181
-						throw new Ks3ClientException("Invalid range ".$range);
182
-					}
183
-				}else{
184
-					if(!isset($range["start"])||!isset($range["end"])){
185
-						throw new Ks3ClientException("Invalid range ".serialize($range));
186
-					}
187
-					if($range["start"] > $range["end"]){
188
-						throw new Ks3ClientException("Invalid range ".serialize($range));
189
-					}
190
-				}
191
-			}
169
+            if(isset($args["Range"])){
170
+                $range = $args["Range"];
171
+                if(!is_array($range)){
172
+                    if(preg_match('/^bytes=[0-9]*-[0-9]*$/', $range)){
173
+                        $ranges = explode("-",substr($range,strlen("bytes=")));
174
+                        $a = $ranges[0];
175
+                        $b = $ranges[1];
176
+                        if($a > $b){
177
+                            throw new Ks3ClientException("Invalid range ".$range);
178
+                        }
179
+                        $range = array("start"=>$a,"end"=>$b);
180
+                    }else{
181
+                        throw new Ks3ClientException("Invalid range ".$range);
182
+                    }
183
+                }else{
184
+                    if(!isset($range["start"])||!isset($range["end"])){
185
+                        throw new Ks3ClientException("Invalid range ".serialize($range));
186
+                    }
187
+                    if($range["start"] > $range["end"]){
188
+                        throw new Ks3ClientException("Invalid range ".serialize($range));
189
+                    }
190
+                }
191
+            }
192 192
 
193
-			$isWriteToFile = isset($args["WriteTo"]);
194
-			$contentLength = $meta["ObjectMeta"]["Content-Length"];
195
-			if($isWriteToFile){
196
-				$writeCallBack = new AESCBCStreamWriteCallBack();
197
-				$writeCallBack->iv=$iv;
198
-				$writeCallBack->cek=$cek;
199
-				$writeCallBack->contentLength = $contentLength;
200
-				if(isset($range)){
201
-					$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
202
-					$adjustedRange = EncryptionUtil::getAdjustedRange($range,$blocksize);
203
-					$writeCallBack->expectedRange = $range;
204
-					$writeCallBack->adjustedRange = $adjustedRange;
205
-					$args["Range"]=$adjustedRange;
206
-				}
207
-				$args["writeCallBack"] = $writeCallBack;
208
-				return $this->ks3client->getObject($args);
209
-			}else{
210
-				$offset = 0;
211
-				$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
212
-				if(isset($range)){
213
-					$adjustedRange = EncryptionUtil::getAdjustedRange($range,$blocksize);
214
-					$args["Range"]=$adjustedRange;
215
-				}
216
-				$s3Object = $this->ks3client->getObject($args);
217
-				$content = $s3Object["Content"];
193
+            $isWriteToFile = isset($args["WriteTo"]);
194
+            $contentLength = $meta["ObjectMeta"]["Content-Length"];
195
+            if($isWriteToFile){
196
+                $writeCallBack = new AESCBCStreamWriteCallBack();
197
+                $writeCallBack->iv=$iv;
198
+                $writeCallBack->cek=$cek;
199
+                $writeCallBack->contentLength = $contentLength;
200
+                if(isset($range)){
201
+                    $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
202
+                    $adjustedRange = EncryptionUtil::getAdjustedRange($range,$blocksize);
203
+                    $writeCallBack->expectedRange = $range;
204
+                    $writeCallBack->adjustedRange = $adjustedRange;
205
+                    $args["Range"]=$adjustedRange;
206
+                }
207
+                $args["writeCallBack"] = $writeCallBack;
208
+                return $this->ks3client->getObject($args);
209
+            }else{
210
+                $offset = 0;
211
+                $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
212
+                if(isset($range)){
213
+                    $adjustedRange = EncryptionUtil::getAdjustedRange($range,$blocksize);
214
+                    $args["Range"]=$adjustedRange;
215
+                }
216
+                $s3Object = $this->ks3client->getObject($args);
217
+                $content = $s3Object["Content"];
218 218
 
219
-				if(isset($range)){
220
-					if($adjustedRange["start"] > 0){
221
-						$iv = substr($content,0,$blocksize);
222
-						$content = substr($content,$blocksize);
223
-						$offset = $blocksize+$adjustedRange["start"];
224
-					}
225
-				}
226
-				if(!empty($content)){
227
-					$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
228
-					mcrypt_generic_init($td,$cek,$iv);
229
-					$decoded = mdecrypt_generic($td,$content);
230
-					mcrypt_generic_deinit($td);
231
-					mcrypt_module_close($td);
232
-				}else{
233
-					$decoded = "";
234
-				}
219
+                if(isset($range)){
220
+                    if($adjustedRange["start"] > 0){
221
+                        $iv = substr($content,0,$blocksize);
222
+                        $content = substr($content,$blocksize);
223
+                        $offset = $blocksize+$adjustedRange["start"];
224
+                    }
225
+                }
226
+                if(!empty($content)){
227
+                    $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
228
+                    mcrypt_generic_init($td,$cek,$iv);
229
+                    $decoded = mdecrypt_generic($td,$content);
230
+                    mcrypt_generic_deinit($td);
231
+                    mcrypt_module_close($td);
232
+                }else{
233
+                    $decoded = "";
234
+                }
235 235
 
236
-				//判断是否需要删除最后填充的字符,以及获取填充的字符
237
-				$needRemovePad = FALSE;
238
-				$pad = NULL;
239
-				if($offset+strlen($decoded) >=$contentLength){
240
-					$needRemovePad = TRUE;
241
-					$pad = ord(substr($decoded,strlen($decoded)-1,1));
242
-					if($pad<=0||$pad>$blocksize)
243
-					{
244
-						//invalid pad
245
-						$needRemovePad = FALSE;
246
-					}
247
-				}
248
-				$endOffset = 0;
249
-				if(isset($range)){
250
-					if($offset+strlen($decoded)>$range["end"]){
251
-						$preLength = strlen($decoded);
252
-						$decoded = substr($decoded, 0,$range["end"]-$offset+1);
253
-						$endOffset = $preLength-strlen($decoded);
254
-					}
255
-					if($offset<$range["start"]){
256
-						$decoded = substr($decoded,$range["start"] - $offset);
257
-					}
258
-				}
259
-				//再次根据截取的长度判断是否需要删除最后填充的字符
260
-				if($needRemovePad&&$endOffset > $pad){
261
-					$needRemovePad = FALSE;
262
-				}
263
-				if($needRemovePad){
264
-					$padOffset = $pad-$endOffset;
265
-					$actualWriteCount = strlen($decoded)-$padOffset;
266
-					if($actualWriteCount <= 0)//负数的情况就是用户期望的range里全是填充的
267
-						$decoded = "";
268
-					else
269
-						$decoded = substr($decoded,0,strlen($decoded)-$padOffset);
270
-				}
271
-				$s3Object["Content"] = $decoded;
272
-				return $s3Object;
273
-			}
274
-		}else{
275
-			return $this->ks3client->getObject($args);
276
-		}
277
-	}
278
-	public function initMultipartUploadSecurely($args=array()){
279
-		$sek = EncryptionUtil::genereateOnceUsedKey();
280
-		$encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials,$sek);
281
-		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
282
-		$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_RAND);
236
+                //判断是否需要删除最后填充的字符,以及获取填充的字符
237
+                $needRemovePad = FALSE;
238
+                $pad = NULL;
239
+                if($offset+strlen($decoded) >=$contentLength){
240
+                    $needRemovePad = TRUE;
241
+                    $pad = ord(substr($decoded,strlen($decoded)-1,1));
242
+                    if($pad<=0||$pad>$blocksize)
243
+                    {
244
+                        //invalid pad
245
+                        $needRemovePad = FALSE;
246
+                    }
247
+                }
248
+                $endOffset = 0;
249
+                if(isset($range)){
250
+                    if($offset+strlen($decoded)>$range["end"]){
251
+                        $preLength = strlen($decoded);
252
+                        $decoded = substr($decoded, 0,$range["end"]-$offset+1);
253
+                        $endOffset = $preLength-strlen($decoded);
254
+                    }
255
+                    if($offset<$range["start"]){
256
+                        $decoded = substr($decoded,$range["start"] - $offset);
257
+                    }
258
+                }
259
+                //再次根据截取的长度判断是否需要删除最后填充的字符
260
+                if($needRemovePad&&$endOffset > $pad){
261
+                    $needRemovePad = FALSE;
262
+                }
263
+                if($needRemovePad){
264
+                    $padOffset = $pad-$endOffset;
265
+                    $actualWriteCount = strlen($decoded)-$padOffset;
266
+                    if($actualWriteCount <= 0)//负数的情况就是用户期望的range里全是填充的
267
+                        $decoded = "";
268
+                    else
269
+                        $decoded = substr($decoded,0,strlen($decoded)-$padOffset);
270
+                }
271
+                $s3Object["Content"] = $decoded;
272
+                return $s3Object;
273
+            }
274
+        }else{
275
+            return $this->ks3client->getObject($args);
276
+        }
277
+    }
278
+    public function initMultipartUploadSecurely($args=array()){
279
+        $sek = EncryptionUtil::genereateOnceUsedKey();
280
+        $encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials,$sek);
281
+        $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
282
+        $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_RAND);
283 283
 		
284
-		$matdesc = "{}";
285
-		if(ENCRYPTPTION_STORAGE_MODE == "ObjectMetadata"){
286
-			$args["UserMeta"]["x-kss-meta-x-kss-key"] = base64_encode($encryptedSek);
287
-			$args["UserMeta"]["x-kss-meta-x-kss-iv"] = base64_encode($iv);
288
-			$args["UserMeta"]["x-kss-meta-x-kss-matdesc"] = $matdesc;
289
-		}
284
+        $matdesc = "{}";
285
+        if(ENCRYPTPTION_STORAGE_MODE == "ObjectMetadata"){
286
+            $args["UserMeta"]["x-kss-meta-x-kss-key"] = base64_encode($encryptedSek);
287
+            $args["UserMeta"]["x-kss-meta-x-kss-iv"] = base64_encode($iv);
288
+            $args["UserMeta"]["x-kss-meta-x-kss-matdesc"] = $matdesc;
289
+        }
290 290
 
291
-		$initResult = $this->ks3client->initMultipartUpload($args);
291
+        $initResult = $this->ks3client->initMultipartUpload($args);
292 292
 
293
-		EncryptionUtil::initMultipartUploadContext($initResult,$iv,$sek,$encryptedSek,$matdesc);
293
+        EncryptionUtil::initMultipartUploadContext($initResult,$iv,$sek,$encryptedSek,$matdesc);
294 294
 
295
-		return $initResult;
296
-	}
297
-	public function uploadPartSecurely($args=array()){
298
-		$uploadId = $args["Options"]["uploadId"];
299
-		$isLastPart = FALSE;
300
-		$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
301
-		if(isset($args["LastPart"]))
302
-			$isLastPart = $args["LastPart"];
303
-		$exists = EncryptionUtil::multipartUploadContextExists($uploadId);
304
-		if(!$exists){
305
-			throw new Ks3ClientException("no such upload in cache/encryption/");
306
-		}
307
-		$context = EncryptionUtil::getMultipartUploadContext($uploadId);
308
-		if($context["lastPart"]){
309
-			throw new Ks3ClientException("this upload with uploadId ".$uploadId," has been upload last part");
310
-		}
311
-		$plainTextLength = EncryptionUtil::plainTextLength($args);
312
-		if($plainTextLength <= 0){
313
-			throw new Ks3ClientException("get content length failed ,unexpected content length ".$plainTextLength);
314
-		}
315
-		if(!$isLastPart){
316
-			if($plainTextLength % $blocksize != 0)
317
-				throw new Ks3ClientException("Invalid part size,part size (".$plainTextLength.") must be multiples of the block size ".$blocksize);
318
-		}else{
319
-			$args["ObjectMeta"]["Content-Length"] = $plainTextLength + ($blocksize - $plainTextLength%$blocksize);
320
-		}
321
-		$readCallBack = new AESCBCStreamReadCallBack();
322
-		$readCallBack->iv = base64_decode($context["nextIv"]);
323
-		$readCallBack->cek = base64_decode($context["cek"]);
324
-		$readCallBack->contentLength = $plainTextLength;
325
-		$readCallBack->mutipartUpload = TRUE;
326
-		$readCallBack->isLastPart = $isLastPart;
327
-		$args["readCallBack"] = $readCallBack;
295
+        return $initResult;
296
+    }
297
+    public function uploadPartSecurely($args=array()){
298
+        $uploadId = $args["Options"]["uploadId"];
299
+        $isLastPart = FALSE;
300
+        $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
301
+        if(isset($args["LastPart"]))
302
+            $isLastPart = $args["LastPart"];
303
+        $exists = EncryptionUtil::multipartUploadContextExists($uploadId);
304
+        if(!$exists){
305
+            throw new Ks3ClientException("no such upload in cache/encryption/");
306
+        }
307
+        $context = EncryptionUtil::getMultipartUploadContext($uploadId);
308
+        if($context["lastPart"]){
309
+            throw new Ks3ClientException("this upload with uploadId ".$uploadId," has been upload last part");
310
+        }
311
+        $plainTextLength = EncryptionUtil::plainTextLength($args);
312
+        if($plainTextLength <= 0){
313
+            throw new Ks3ClientException("get content length failed ,unexpected content length ".$plainTextLength);
314
+        }
315
+        if(!$isLastPart){
316
+            if($plainTextLength % $blocksize != 0)
317
+                throw new Ks3ClientException("Invalid part size,part size (".$plainTextLength.") must be multiples of the block size ".$blocksize);
318
+        }else{
319
+            $args["ObjectMeta"]["Content-Length"] = $plainTextLength + ($blocksize - $plainTextLength%$blocksize);
320
+        }
321
+        $readCallBack = new AESCBCStreamReadCallBack();
322
+        $readCallBack->iv = base64_decode($context["nextIv"]);
323
+        $readCallBack->cek = base64_decode($context["cek"]);
324
+        $readCallBack->contentLength = $plainTextLength;
325
+        $readCallBack->mutipartUpload = TRUE;
326
+        $readCallBack->isLastPart = $isLastPart;
327
+        $args["readCallBack"] = $readCallBack;
328 328
 
329
-		$upResult = $this->ks3client->uploadPart($args);
330
-		EncryptionUtil::updateMultipartUploadContext($uploadId,$readCallBack->iv,$isLastPart);
331
-		return $upResult;
332
-	}
333
-	public function abortMultipartUploadSecurely($args=array()){
334
-		$uploadId = $args["Options"]["uploadId"];
335
-		EncryptionUtil::deleteMultipartUploadContext($uploadId);
336
-		return $this->ks3client->abortMultipartUpload($args);
337
-	}
338
-	public function completeMultipartUploadSecurely($args=array()){
339
-		$uploadId = $args["Options"]["uploadId"];
340
-		$exists = EncryptionUtil::multipartUploadContextExists($uploadId);
341
-		if(!$exists){
342
-			throw new Ks3ClientException("no such upload in cache/encryption/");
343
-		}
344
-		$context = EncryptionUtil::getMultipartUploadContext($uploadId);
345
-		if(!$context["lastPart"]){
346
-			throw new Ks3ClientException("Unable to complete an encrypted multipart upload without being told which part was the last. when upload part you can add item in args like args[\"LastPart\"]=TRUE");
347
-		}
348
-		$result = $this->ks3client->completeMultipartUpload($args);
349
-		if(ENCRYPTPTION_STORAGE_MODE=="InstructionFile"){
350
-			$req = EncryptionUtil::createInstructionFile($args["Bucket"],$args["Key"],
351
-			$context["encryptedCek"],$context["firstIv"],$context["matdesc"]);
352
-			$this->ks3client->putObjectByContent($req);
353
-		}
354
-		EncryptionUtil::deleteMultipartUploadContext($uploadId);
355
-		return $result;
356
-	}
329
+        $upResult = $this->ks3client->uploadPart($args);
330
+        EncryptionUtil::updateMultipartUploadContext($uploadId,$readCallBack->iv,$isLastPart);
331
+        return $upResult;
332
+    }
333
+    public function abortMultipartUploadSecurely($args=array()){
334
+        $uploadId = $args["Options"]["uploadId"];
335
+        EncryptionUtil::deleteMultipartUploadContext($uploadId);
336
+        return $this->ks3client->abortMultipartUpload($args);
337
+    }
338
+    public function completeMultipartUploadSecurely($args=array()){
339
+        $uploadId = $args["Options"]["uploadId"];
340
+        $exists = EncryptionUtil::multipartUploadContextExists($uploadId);
341
+        if(!$exists){
342
+            throw new Ks3ClientException("no such upload in cache/encryption/");
343
+        }
344
+        $context = EncryptionUtil::getMultipartUploadContext($uploadId);
345
+        if(!$context["lastPart"]){
346
+            throw new Ks3ClientException("Unable to complete an encrypted multipart upload without being told which part was the last. when upload part you can add item in args like args[\"LastPart\"]=TRUE");
347
+        }
348
+        $result = $this->ks3client->completeMultipartUpload($args);
349
+        if(ENCRYPTPTION_STORAGE_MODE=="InstructionFile"){
350
+            $req = EncryptionUtil::createInstructionFile($args["Bucket"],$args["Key"],
351
+            $context["encryptedCek"],$context["firstIv"],$context["matdesc"]);
352
+            $this->ks3client->putObjectByContent($req);
353
+        }
354
+        EncryptionUtil::deleteMultipartUploadContext($uploadId);
355
+        return $result;
356
+    }
357 357
 }
358 358
 ?>
359 359
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -2,47 +2,47 @@  discard block
 block discarded – undo
2 2
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR."EncryptionUtil.php";
3 3
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR."EncryptionCallBack.php";
4 4
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php";
5
-interface EncryptionHandler{
6
-	public function putObjectByContentSecurely($args=array());
7
-	public function putObjectByFileSecurely($args=array());
8
-	public function getObjectSecurely($args=array());
9
-	public function initMultipartUploadSecurely($args=array());
10
-	public function uploadPartSecurely($args=array());
11
-	public function abortMultipartUploadSecurely($args=array());
12
-	public function completeMultipartUploadSecurely($args=array());
5
+interface EncryptionHandler {
6
+	public function putObjectByContentSecurely($args = array());
7
+	public function putObjectByFileSecurely($args = array());
8
+	public function getObjectSecurely($args = array());
9
+	public function initMultipartUploadSecurely($args = array());
10
+	public function uploadPartSecurely($args = array());
11
+	public function abortMultipartUploadSecurely($args = array());
12
+	public function completeMultipartUploadSecurely($args = array());
13 13
 }
14
-class EncryptionEO implements EncryptionHandler{
14
+class EncryptionEO implements EncryptionHandler {
15 15
 	private $encryptionMaterials = NULL;
16 16
 	private $ks3client = NULL;
17
-	public function __construct($ks3client,$encryptionMaterials){
17
+	public function __construct($ks3client, $encryptionMaterials) {
18 18
 		$this->encryptionMaterials = $encryptionMaterials;
19 19
 		$this->ks3client = $ks3client;
20 20
 	}
21
-	public function putObjectByContentSecurely($args=array()){
21
+	public function putObjectByContentSecurely($args = array()) {
22 22
 		$sek = EncryptionUtil::genereateOnceUsedKey();
23
-		$encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials,$sek);
23
+		$encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials, $sek);
24 24
 		$content = $args["Content"];
25
-		if(empty($content))
25
+		if (empty($content))
26 26
 			throw new Ks3ClientException("please specifie Content in request args");
27 27
 		$metaContentLength = EncryptionUtil::metaTextLength($args);
28 28
 		$plainTextLength = strlen($content);
29
-		if($metaContentLength > 0 && $metaContentLength < $plainTextLength){
29
+		if ($metaContentLength > 0 && $metaContentLength < $plainTextLength) {
30 30
 			$plainTextLength = $metaContentLength;
31 31
 		}
32
-		if($plainTextLength > 0)
32
+		if ($plainTextLength > 0)
33 33
 			$args["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-length"] = $plainTextLength;
34 34
 		else
35 35
 			throw new Ks3ClientException("unexpected content length ".$plainTextLength);
36 36
 
37
-		$content =  substr($content, 0,$plainTextLength);
37
+		$content = substr($content, 0, $plainTextLength);
38 38
 
39 39
 
40
-		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
41
-		$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_RAND);
42
-		mcrypt_generic_init($td,$sek,$iv);
40
+		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
41
+		$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
42
+		mcrypt_generic_init($td, $sek, $iv);
43 43
 		//对content进行pkcs5填充
44
-		$content = EncryptionUtil::PKCS5Padding($content,mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC));
45
-		$encrypted = mcrypt_generic($td,$content);
44
+		$content = EncryptionUtil::PKCS5Padding($content, mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
45
+		$encrypted = mcrypt_generic($td, $content);
46 46
 		mcrypt_generic_deinit($td);
47 47
 
48 48
 		$args["ObjectMeta"]["Content-Length"] = strlen($encrypted);
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 
53 53
 		//TODO
54 54
 		$matdesc = "{}";
55
-		if(ENCRYPTPTION_STORAGE_MODE == "ObjectMetadata"){
55
+		if (ENCRYPTPTION_STORAGE_MODE == "ObjectMetadata") {
56 56
 			$args["UserMeta"]["x-kss-meta-x-kss-key"] = base64_encode($encryptedSek);
57 57
 			$args["UserMeta"]["x-kss-meta-x-kss-iv"] = base64_encode($iv);
58 58
 			$args["UserMeta"]["x-kss-meta-x-kss-matdesc"] = $matdesc;
@@ -60,31 +60,31 @@  discard block
 block discarded – undo
60 60
 
61 61
 		$result = $this->ks3client->putObjectByContent($args);
62 62
 
63
-		if(ENCRYPTPTION_STORAGE_MODE == "InstructionFile"){
64
-			$req = EncryptionUtil::createInstructionFile($args["Bucket"],$args["Key"],
65
-			base64_encode($encryptedSek),base64_encode($iv),$matdesc);
63
+		if (ENCRYPTPTION_STORAGE_MODE == "InstructionFile") {
64
+			$req = EncryptionUtil::createInstructionFile($args["Bucket"], $args["Key"],
65
+			base64_encode($encryptedSek), base64_encode($iv), $matdesc);
66 66
 			$this->ks3client->putObjectByContent($req);
67 67
 		}
68 68
 
69 69
 		return $result;
70 70
 	}
71
-	public function putObjectByFileSecurely($args=array()){
71
+	public function putObjectByFileSecurely($args = array()) {
72 72
 		$sek = EncryptionUtil::genereateOnceUsedKey();
73
-		$encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials,$sek);
74
-		if(!isset($args["Content"])||!is_array($args["Content"])
73
+		$encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials, $sek);
74
+		if (!isset($args["Content"]) || !is_array($args["Content"])
75 75
 			||!isset($args["Content"]["content"])
76 76
 			||empty($args["Content"]["content"]))
77 77
 			throw new Ks3ClientException("please specifie file content in request args");
78 78
 		$content = $args["Content"];
79 79
 		$plainTextLength = EncryptionUtil::plainTextLength($args);
80
-		if($plainTextLength <= 0){
80
+		if ($plainTextLength <= 0) {
81 81
 			throw new Ks3ClientException("get content length failed ,unexpected content length ".$plainTextLength);
82 82
 		}
83
-		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
84
-		$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_RAND);
83
+		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
84
+		$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
85 85
 
86 86
 		$args = EncryptionUtil::updateContentMD5Header($args);
87
-		$encryptedLength = EncryptionUtil::getPKCS5EncrypedLength($plainTextLength,mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC));
87
+		$encryptedLength = EncryptionUtil::getPKCS5EncrypedLength($plainTextLength, mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
88 88
 
89 89
 		$args["ObjectMeta"]["Content-Length"] = $encryptedLength;
90 90
 		$args["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-length"] = $plainTextLength;
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 
98 98
 		//TODO
99 99
 		$matdesc = "{}";
100
-		if(ENCRYPTPTION_STORAGE_MODE == "ObjectMetadata"){
100
+		if (ENCRYPTPTION_STORAGE_MODE == "ObjectMetadata") {
101 101
 			$args["UserMeta"]["x-kss-meta-x-kss-key"] = base64_encode($encryptedSek);
102 102
 			$args["UserMeta"]["x-kss-meta-x-kss-iv"] = base64_encode($iv);
103 103
 			$args["UserMeta"]["x-kss-meta-x-kss-matdesc"] = $matdesc;
@@ -105,86 +105,86 @@  discard block
 block discarded – undo
105 105
 
106 106
 		$result = $this->ks3client->putObjectByFile($args);
107 107
 
108
-		if(ENCRYPTPTION_STORAGE_MODE == "InstructionFile"){
109
-			$req = EncryptionUtil::createInstructionFile($args["Bucket"],$args["Key"],
110
-			base64_encode($encryptedSek),base64_encode($iv),$matdesc);
108
+		if (ENCRYPTPTION_STORAGE_MODE == "InstructionFile") {
109
+			$req = EncryptionUtil::createInstructionFile($args["Bucket"], $args["Key"],
110
+			base64_encode($encryptedSek), base64_encode($iv), $matdesc);
111 111
 			$this->ks3client->putObjectByContent($req);
112 112
 		}
113 113
 
114 114
 		return $result;
115 115
 	}
116
-	public function getObjectSecurely($args=array()){
116
+	public function getObjectSecurely($args = array()) {
117 117
 		$meta = $this->ks3client->getObjectMeta($args);
118
-		if(isset($meta["UserMeta"]["x-kss-meta-x-kss-key"])&&isset($meta["UserMeta"]["x-kss-meta-x-kss-iv"])){
118
+		if (isset($meta["UserMeta"]["x-kss-meta-x-kss-key"]) && isset($meta["UserMeta"]["x-kss-meta-x-kss-iv"])) {
119 119
 			$encryptedInMeta = TRUE;
120
-		}else{
120
+		}else {
121 121
 			$encryptedInMeta = FALSE;
122 122
 		}
123 123
 		$encrypted = TRUE;
124 124
 		$encryptionInfo = array();
125
-		if($encryptedInMeta){
125
+		if ($encryptedInMeta) {
126 126
 			$encryptionInfo["iv"] = base64_decode($meta["UserMeta"]["x-kss-meta-x-kss-iv"]);
127
-			$matdesc =$meta["UserMeta"]["x-kss-meta-x-kss-matdesc"];
127
+			$matdesc = $meta["UserMeta"]["x-kss-meta-x-kss-matdesc"];
128 128
 			$encryptionInfo["matdesc"] = $matdesc;
129 129
 			$cekEncrypted = base64_decode($meta["UserMeta"]["x-kss-meta-x-kss-key"]);
130
-			$encryptionInfo["cek"] = $cek = EncryptionUtil::decodeCek($this->encryptionMaterials,$cekEncrypted);
131
-		}else{
132
-			if($this->ks3client->objectExists(array(
130
+			$encryptionInfo["cek"] = $cek = EncryptionUtil::decodeCek($this->encryptionMaterials, $cekEncrypted);
131
+		}else {
132
+			if ($this->ks3client->objectExists(array(
133 133
 				"Bucket"=>$args["Bucket"],
134 134
 				"Key"=>$args["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX)
135 135
 				)
136
-			){
136
+			) {
137 137
 				$insKey = $args["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX;
138 138
 				$getIns = array(
139 139
 					"Bucket"=>$args["Bucket"],
140 140
 					"Key"=>$insKey,
141 141
 				);
142 142
 				$s3Object = $this->ks3client->getObject($getIns);
143
-				if(!EncryptionUtil::isInstructionFile($s3Object))
143
+				if (!EncryptionUtil::isInstructionFile($s3Object))
144 144
 					throw new Ks3ClientException($insKey." is not an InstructionFile");
145 145
 
146 146
 				$content = $s3Object["Content"];
147
-				$content = json_decode($content,TRUE);
147
+				$content = json_decode($content, TRUE);
148 148
 				$encryptionInfo["iv"] = base64_decode($content["x-kss-iv"]);
149
-				$matdesc =$content["x-kss-matdesc"];
149
+				$matdesc = $content["x-kss-matdesc"];
150 150
 				$encryptionInfo["matdesc"] = $matdesc;
151 151
 				$cekEncrypted = base64_decode($content["x-kss-key"]);
152
-				$encryptionInfo["cek"] = $cek = EncryptionUtil::decodeCek($this->encryptionMaterials,$cekEncrypted);
153
-			}else{
154
-				$encrypted =FALSE;
152
+				$encryptionInfo["cek"] = $cek = EncryptionUtil::decodeCek($this->encryptionMaterials, $cekEncrypted);
153
+			}else {
154
+				$encrypted = FALSE;
155 155
 			}
156 156
 		}
157 157
 		//是否为下载到文件中
158
-		$isWriteToFile=FALSE;
159
-		if($encrypted)
158
+		$isWriteToFile = FALSE;
159
+		if ($encrypted)
160 160
 		{
161 161
 			$iv = $encryptionInfo["iv"];
162 162
 			$cek = $encryptionInfo["cek"];
163 163
 
164
-			if(empty($iv))
164
+			if (empty($iv))
165 165
 				throw new Ks3ClientException("can not find iv in UserMeta or InstructionFile");
166
-			if(empty($cek))
166
+			if (empty($cek))
167 167
 				throw new Ks3ClientException("can not find cek in UserMeta or InstructionFile");
168 168
 
169
-			if(isset($args["Range"])){
169
+			if (isset($args["Range"])) {
170 170
 				$range = $args["Range"];
171
-				if(!is_array($range)){
172
-					if(preg_match('/^bytes=[0-9]*-[0-9]*$/', $range)){
173
-						$ranges = explode("-",substr($range,strlen("bytes=")));
171
+				if (!is_array($range)) {
172
+					if (preg_match('/^bytes=[0-9]*-[0-9]*$/', $range)) {
173
+						$ranges = explode("-", substr($range, strlen("bytes=")));
174 174
 						$a = $ranges[0];
175 175
 						$b = $ranges[1];
176
-						if($a > $b){
176
+						if ($a > $b) {
177 177
 							throw new Ks3ClientException("Invalid range ".$range);
178 178
 						}
179
-						$range = array("start"=>$a,"end"=>$b);
180
-					}else{
179
+						$range = array("start"=>$a, "end"=>$b);
180
+					}else {
181 181
 						throw new Ks3ClientException("Invalid range ".$range);
182 182
 					}
183
-				}else{
184
-					if(!isset($range["start"])||!isset($range["end"])){
183
+				}else {
184
+					if (!isset($range["start"]) || !isset($range["end"])) {
185 185
 						throw new Ks3ClientException("Invalid range ".serialize($range));
186 186
 					}
187
-					if($range["start"] > $range["end"]){
187
+					if ($range["start"] > $range["end"]) {
188 188
 						throw new Ks3ClientException("Invalid range ".serialize($range));
189 189
 					}
190 190
 				}
@@ -192,97 +192,97 @@  discard block
 block discarded – undo
192 192
 
193 193
 			$isWriteToFile = isset($args["WriteTo"]);
194 194
 			$contentLength = $meta["ObjectMeta"]["Content-Length"];
195
-			if($isWriteToFile){
195
+			if ($isWriteToFile) {
196 196
 				$writeCallBack = new AESCBCStreamWriteCallBack();
197
-				$writeCallBack->iv=$iv;
198
-				$writeCallBack->cek=$cek;
197
+				$writeCallBack->iv = $iv;
198
+				$writeCallBack->cek = $cek;
199 199
 				$writeCallBack->contentLength = $contentLength;
200
-				if(isset($range)){
201
-					$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
202
-					$adjustedRange = EncryptionUtil::getAdjustedRange($range,$blocksize);
200
+				if (isset($range)) {
201
+					$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
202
+					$adjustedRange = EncryptionUtil::getAdjustedRange($range, $blocksize);
203 203
 					$writeCallBack->expectedRange = $range;
204 204
 					$writeCallBack->adjustedRange = $adjustedRange;
205
-					$args["Range"]=$adjustedRange;
205
+					$args["Range"] = $adjustedRange;
206 206
 				}
207 207
 				$args["writeCallBack"] = $writeCallBack;
208 208
 				return $this->ks3client->getObject($args);
209
-			}else{
209
+			}else {
210 210
 				$offset = 0;
211
-				$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
212
-				if(isset($range)){
213
-					$adjustedRange = EncryptionUtil::getAdjustedRange($range,$blocksize);
214
-					$args["Range"]=$adjustedRange;
211
+				$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
212
+				if (isset($range)) {
213
+					$adjustedRange = EncryptionUtil::getAdjustedRange($range, $blocksize);
214
+					$args["Range"] = $adjustedRange;
215 215
 				}
216 216
 				$s3Object = $this->ks3client->getObject($args);
217 217
 				$content = $s3Object["Content"];
218 218
 
219
-				if(isset($range)){
220
-					if($adjustedRange["start"] > 0){
221
-						$iv = substr($content,0,$blocksize);
222
-						$content = substr($content,$blocksize);
219
+				if (isset($range)) {
220
+					if ($adjustedRange["start"] > 0) {
221
+						$iv = substr($content, 0, $blocksize);
222
+						$content = substr($content, $blocksize);
223 223
 						$offset = $blocksize+$adjustedRange["start"];
224 224
 					}
225 225
 				}
226
-				if(!empty($content)){
227
-					$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
228
-					mcrypt_generic_init($td,$cek,$iv);
229
-					$decoded = mdecrypt_generic($td,$content);
226
+				if (!empty($content)) {
227
+					$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
228
+					mcrypt_generic_init($td, $cek, $iv);
229
+					$decoded = mdecrypt_generic($td, $content);
230 230
 					mcrypt_generic_deinit($td);
231 231
 					mcrypt_module_close($td);
232
-				}else{
232
+				}else {
233 233
 					$decoded = "";
234 234
 				}
235 235
 
236 236
 				//判断是否需要删除最后填充的字符,以及获取填充的字符
237 237
 				$needRemovePad = FALSE;
238 238
 				$pad = NULL;
239
-				if($offset+strlen($decoded) >=$contentLength){
239
+				if ($offset+strlen($decoded) >= $contentLength) {
240 240
 					$needRemovePad = TRUE;
241
-					$pad = ord(substr($decoded,strlen($decoded)-1,1));
242
-					if($pad<=0||$pad>$blocksize)
241
+					$pad = ord(substr($decoded, strlen($decoded)-1, 1));
242
+					if ($pad <= 0 || $pad > $blocksize)
243 243
 					{
244 244
 						//invalid pad
245 245
 						$needRemovePad = FALSE;
246 246
 					}
247 247
 				}
248 248
 				$endOffset = 0;
249
-				if(isset($range)){
250
-					if($offset+strlen($decoded)>$range["end"]){
249
+				if (isset($range)) {
250
+					if ($offset+strlen($decoded) > $range["end"]) {
251 251
 						$preLength = strlen($decoded);
252
-						$decoded = substr($decoded, 0,$range["end"]-$offset+1);
252
+						$decoded = substr($decoded, 0, $range["end"]-$offset+1);
253 253
 						$endOffset = $preLength-strlen($decoded);
254 254
 					}
255
-					if($offset<$range["start"]){
256
-						$decoded = substr($decoded,$range["start"] - $offset);
255
+					if ($offset < $range["start"]) {
256
+						$decoded = substr($decoded, $range["start"]-$offset);
257 257
 					}
258 258
 				}
259 259
 				//再次根据截取的长度判断是否需要删除最后填充的字符
260
-				if($needRemovePad&&$endOffset > $pad){
260
+				if ($needRemovePad && $endOffset > $pad) {
261 261
 					$needRemovePad = FALSE;
262 262
 				}
263
-				if($needRemovePad){
263
+				if ($needRemovePad) {
264 264
 					$padOffset = $pad-$endOffset;
265 265
 					$actualWriteCount = strlen($decoded)-$padOffset;
266
-					if($actualWriteCount <= 0)//负数的情况就是用户期望的range里全是填充的
266
+					if ($actualWriteCount <= 0)//负数的情况就是用户期望的range里全是填充的
267 267
 						$decoded = "";
268 268
 					else
269
-						$decoded = substr($decoded,0,strlen($decoded)-$padOffset);
269
+						$decoded = substr($decoded, 0, strlen($decoded)-$padOffset);
270 270
 				}
271 271
 				$s3Object["Content"] = $decoded;
272 272
 				return $s3Object;
273 273
 			}
274
-		}else{
274
+		}else {
275 275
 			return $this->ks3client->getObject($args);
276 276
 		}
277 277
 	}
278
-	public function initMultipartUploadSecurely($args=array()){
278
+	public function initMultipartUploadSecurely($args = array()) {
279 279
 		$sek = EncryptionUtil::genereateOnceUsedKey();
280
-		$encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials,$sek);
281
-		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
282
-		$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),MCRYPT_RAND);
280
+		$encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials, $sek);
281
+		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
282
+		$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
283 283
 		
284 284
 		$matdesc = "{}";
285
-		if(ENCRYPTPTION_STORAGE_MODE == "ObjectMetadata"){
285
+		if (ENCRYPTPTION_STORAGE_MODE == "ObjectMetadata") {
286 286
 			$args["UserMeta"]["x-kss-meta-x-kss-key"] = base64_encode($encryptedSek);
287 287
 			$args["UserMeta"]["x-kss-meta-x-kss-iv"] = base64_encode($iv);
288 288
 			$args["UserMeta"]["x-kss-meta-x-kss-matdesc"] = $matdesc;
@@ -290,33 +290,33 @@  discard block
 block discarded – undo
290 290
 
291 291
 		$initResult = $this->ks3client->initMultipartUpload($args);
292 292
 
293
-		EncryptionUtil::initMultipartUploadContext($initResult,$iv,$sek,$encryptedSek,$matdesc);
293
+		EncryptionUtil::initMultipartUploadContext($initResult, $iv, $sek, $encryptedSek, $matdesc);
294 294
 
295 295
 		return $initResult;
296 296
 	}
297
-	public function uploadPartSecurely($args=array()){
297
+	public function uploadPartSecurely($args = array()) {
298 298
 		$uploadId = $args["Options"]["uploadId"];
299 299
 		$isLastPart = FALSE;
300
-		$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
301
-		if(isset($args["LastPart"]))
300
+		$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
301
+		if (isset($args["LastPart"]))
302 302
 			$isLastPart = $args["LastPart"];
303 303
 		$exists = EncryptionUtil::multipartUploadContextExists($uploadId);
304
-		if(!$exists){
304
+		if (!$exists) {
305 305
 			throw new Ks3ClientException("no such upload in cache/encryption/");
306 306
 		}
307 307
 		$context = EncryptionUtil::getMultipartUploadContext($uploadId);
308
-		if($context["lastPart"]){
309
-			throw new Ks3ClientException("this upload with uploadId ".$uploadId," has been upload last part");
308
+		if ($context["lastPart"]) {
309
+			throw new Ks3ClientException("this upload with uploadId ".$uploadId, " has been upload last part");
310 310
 		}
311 311
 		$plainTextLength = EncryptionUtil::plainTextLength($args);
312
-		if($plainTextLength <= 0){
312
+		if ($plainTextLength <= 0) {
313 313
 			throw new Ks3ClientException("get content length failed ,unexpected content length ".$plainTextLength);
314 314
 		}
315
-		if(!$isLastPart){
316
-			if($plainTextLength % $blocksize != 0)
315
+		if (!$isLastPart) {
316
+			if ($plainTextLength%$blocksize != 0)
317 317
 				throw new Ks3ClientException("Invalid part size,part size (".$plainTextLength.") must be multiples of the block size ".$blocksize);
318
-		}else{
319
-			$args["ObjectMeta"]["Content-Length"] = $plainTextLength + ($blocksize - $plainTextLength%$blocksize);
318
+		}else {
319
+			$args["ObjectMeta"]["Content-Length"] = $plainTextLength+($blocksize-$plainTextLength%$blocksize);
320 320
 		}
321 321
 		$readCallBack = new AESCBCStreamReadCallBack();
322 322
 		$readCallBack->iv = base64_decode($context["nextIv"]);
@@ -327,28 +327,28 @@  discard block
 block discarded – undo
327 327
 		$args["readCallBack"] = $readCallBack;
328 328
 
329 329
 		$upResult = $this->ks3client->uploadPart($args);
330
-		EncryptionUtil::updateMultipartUploadContext($uploadId,$readCallBack->iv,$isLastPart);
330
+		EncryptionUtil::updateMultipartUploadContext($uploadId, $readCallBack->iv, $isLastPart);
331 331
 		return $upResult;
332 332
 	}
333
-	public function abortMultipartUploadSecurely($args=array()){
333
+	public function abortMultipartUploadSecurely($args = array()) {
334 334
 		$uploadId = $args["Options"]["uploadId"];
335 335
 		EncryptionUtil::deleteMultipartUploadContext($uploadId);
336 336
 		return $this->ks3client->abortMultipartUpload($args);
337 337
 	}
338
-	public function completeMultipartUploadSecurely($args=array()){
338
+	public function completeMultipartUploadSecurely($args = array()) {
339 339
 		$uploadId = $args["Options"]["uploadId"];
340 340
 		$exists = EncryptionUtil::multipartUploadContextExists($uploadId);
341
-		if(!$exists){
341
+		if (!$exists) {
342 342
 			throw new Ks3ClientException("no such upload in cache/encryption/");
343 343
 		}
344 344
 		$context = EncryptionUtil::getMultipartUploadContext($uploadId);
345
-		if(!$context["lastPart"]){
345
+		if (!$context["lastPart"]) {
346 346
 			throw new Ks3ClientException("Unable to complete an encrypted multipart upload without being told which part was the last. when upload part you can add item in args like args[\"LastPart\"]=TRUE");
347 347
 		}
348 348
 		$result = $this->ks3client->completeMultipartUpload($args);
349
-		if(ENCRYPTPTION_STORAGE_MODE=="InstructionFile"){
350
-			$req = EncryptionUtil::createInstructionFile($args["Bucket"],$args["Key"],
351
-			$context["encryptedCek"],$context["firstIv"],$context["matdesc"]);
349
+		if (ENCRYPTPTION_STORAGE_MODE == "InstructionFile") {
350
+			$req = EncryptionUtil::createInstructionFile($args["Bucket"], $args["Key"],
351
+			$context["encryptedCek"], $context["firstIv"], $context["matdesc"]);
352 352
 			$this->ks3client->putObjectByContent($req);
353 353
 		}
354 354
 		EncryptionUtil::deleteMultipartUploadContext($uploadId);
Please login to merge, or discard this patch.
Braces   +40 added lines, -30 removed lines patch added patch discarded remove patch
@@ -22,17 +22,19 @@  discard block
 block discarded – undo
22 22
 		$sek = EncryptionUtil::genereateOnceUsedKey();
23 23
 		$encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials,$sek);
24 24
 		$content = $args["Content"];
25
-		if(empty($content))
26
-			throw new Ks3ClientException("please specifie Content in request args");
25
+		if(empty($content)) {
26
+					throw new Ks3ClientException("please specifie Content in request args");
27
+		}
27 28
 		$metaContentLength = EncryptionUtil::metaTextLength($args);
28 29
 		$plainTextLength = strlen($content);
29 30
 		if($metaContentLength > 0 && $metaContentLength < $plainTextLength){
30 31
 			$plainTextLength = $metaContentLength;
31 32
 		}
32
-		if($plainTextLength > 0)
33
-			$args["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-length"] = $plainTextLength;
34
-		else
35
-			throw new Ks3ClientException("unexpected content length ".$plainTextLength);
33
+		if($plainTextLength > 0) {
34
+					$args["UserMeta"]["x-kss-meta-x-kss-unencrypted-content-length"] = $plainTextLength;
35
+		} else {
36
+					throw new Ks3ClientException("unexpected content length ".$plainTextLength);
37
+		}
36 38
 
37 39
 		$content =  substr($content, 0,$plainTextLength);
38 40
 
@@ -73,8 +75,9 @@  discard block
 block discarded – undo
73 75
 		$encryptedSek = EncryptionUtil::encodeCek($this->encryptionMaterials,$sek);
74 76
 		if(!isset($args["Content"])||!is_array($args["Content"])
75 77
 			||!isset($args["Content"]["content"])
76
-			||empty($args["Content"]["content"]))
77
-			throw new Ks3ClientException("please specifie file content in request args");
78
+			||empty($args["Content"]["content"])) {
79
+					throw new Ks3ClientException("please specifie file content in request args");
80
+		}
78 81
 		$content = $args["Content"];
79 82
 		$plainTextLength = EncryptionUtil::plainTextLength($args);
80 83
 		if($plainTextLength <= 0){
@@ -117,7 +120,7 @@  discard block
 block discarded – undo
117 120
 		$meta = $this->ks3client->getObjectMeta($args);
118 121
 		if(isset($meta["UserMeta"]["x-kss-meta-x-kss-key"])&&isset($meta["UserMeta"]["x-kss-meta-x-kss-iv"])){
119 122
 			$encryptedInMeta = TRUE;
120
-		}else{
123
+		} else{
121 124
 			$encryptedInMeta = FALSE;
122 125
 		}
123 126
 		$encrypted = TRUE;
@@ -128,7 +131,7 @@  discard block
 block discarded – undo
128 131
 			$encryptionInfo["matdesc"] = $matdesc;
129 132
 			$cekEncrypted = base64_decode($meta["UserMeta"]["x-kss-meta-x-kss-key"]);
130 133
 			$encryptionInfo["cek"] = $cek = EncryptionUtil::decodeCek($this->encryptionMaterials,$cekEncrypted);
131
-		}else{
134
+		} else{
132 135
 			if($this->ks3client->objectExists(array(
133 136
 				"Bucket"=>$args["Bucket"],
134 137
 				"Key"=>$args["Key"].EncryptionUtil::$INSTRUCTION_SUFFIX)
@@ -140,8 +143,9 @@  discard block
 block discarded – undo
140 143
 					"Key"=>$insKey,
141 144
 				);
142 145
 				$s3Object = $this->ks3client->getObject($getIns);
143
-				if(!EncryptionUtil::isInstructionFile($s3Object))
144
-					throw new Ks3ClientException($insKey." is not an InstructionFile");
146
+				if(!EncryptionUtil::isInstructionFile($s3Object)) {
147
+									throw new Ks3ClientException($insKey." is not an InstructionFile");
148
+				}
145 149
 
146 150
 				$content = $s3Object["Content"];
147 151
 				$content = json_decode($content,TRUE);
@@ -150,7 +154,7 @@  discard block
 block discarded – undo
150 154
 				$encryptionInfo["matdesc"] = $matdesc;
151 155
 				$cekEncrypted = base64_decode($content["x-kss-key"]);
152 156
 				$encryptionInfo["cek"] = $cek = EncryptionUtil::decodeCek($this->encryptionMaterials,$cekEncrypted);
153
-			}else{
157
+			} else{
154 158
 				$encrypted =FALSE;
155 159
 			}
156 160
 		}
@@ -161,10 +165,12 @@  discard block
 block discarded – undo
161 165
 			$iv = $encryptionInfo["iv"];
162 166
 			$cek = $encryptionInfo["cek"];
163 167
 
164
-			if(empty($iv))
165
-				throw new Ks3ClientException("can not find iv in UserMeta or InstructionFile");
166
-			if(empty($cek))
167
-				throw new Ks3ClientException("can not find cek in UserMeta or InstructionFile");
168
+			if(empty($iv)) {
169
+							throw new Ks3ClientException("can not find iv in UserMeta or InstructionFile");
170
+			}
171
+			if(empty($cek)) {
172
+							throw new Ks3ClientException("can not find cek in UserMeta or InstructionFile");
173
+			}
168 174
 
169 175
 			if(isset($args["Range"])){
170 176
 				$range = $args["Range"];
@@ -177,10 +183,10 @@  discard block
 block discarded – undo
177 183
 							throw new Ks3ClientException("Invalid range ".$range);
178 184
 						}
179 185
 						$range = array("start"=>$a,"end"=>$b);
180
-					}else{
186
+					} else{
181 187
 						throw new Ks3ClientException("Invalid range ".$range);
182 188
 					}
183
-				}else{
189
+				} else{
184 190
 					if(!isset($range["start"])||!isset($range["end"])){
185 191
 						throw new Ks3ClientException("Invalid range ".serialize($range));
186 192
 					}
@@ -206,7 +212,7 @@  discard block
 block discarded – undo
206 212
 				}
207 213
 				$args["writeCallBack"] = $writeCallBack;
208 214
 				return $this->ks3client->getObject($args);
209
-			}else{
215
+			} else{
210 216
 				$offset = 0;
211 217
 				$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
212 218
 				if(isset($range)){
@@ -229,7 +235,7 @@  discard block
 block discarded – undo
229 235
 					$decoded = mdecrypt_generic($td,$content);
230 236
 					mcrypt_generic_deinit($td);
231 237
 					mcrypt_module_close($td);
232
-				}else{
238
+				} else{
233 239
 					$decoded = "";
234 240
 				}
235 241
 
@@ -263,15 +269,17 @@  discard block
 block discarded – undo
263 269
 				if($needRemovePad){
264 270
 					$padOffset = $pad-$endOffset;
265 271
 					$actualWriteCount = strlen($decoded)-$padOffset;
266
-					if($actualWriteCount <= 0)//负数的情况就是用户期望的range里全是填充的
272
+					if($actualWriteCount <= 0) {
273
+					    //负数的情况就是用户期望的range里全是填充的
267 274
 						$decoded = "";
268
-					else
269
-						$decoded = substr($decoded,0,strlen($decoded)-$padOffset);
275
+					} else {
276
+											$decoded = substr($decoded,0,strlen($decoded)-$padOffset);
277
+					}
270 278
 				}
271 279
 				$s3Object["Content"] = $decoded;
272 280
 				return $s3Object;
273 281
 			}
274
-		}else{
282
+		} else{
275 283
 			return $this->ks3client->getObject($args);
276 284
 		}
277 285
 	}
@@ -298,8 +306,9 @@  discard block
 block discarded – undo
298 306
 		$uploadId = $args["Options"]["uploadId"];
299 307
 		$isLastPart = FALSE;
300 308
 		$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
301
-		if(isset($args["LastPart"]))
302
-			$isLastPart = $args["LastPart"];
309
+		if(isset($args["LastPart"])) {
310
+					$isLastPart = $args["LastPart"];
311
+		}
303 312
 		$exists = EncryptionUtil::multipartUploadContextExists($uploadId);
304 313
 		if(!$exists){
305 314
 			throw new Ks3ClientException("no such upload in cache/encryption/");
@@ -313,9 +322,10 @@  discard block
 block discarded – undo
313 322
 			throw new Ks3ClientException("get content length failed ,unexpected content length ".$plainTextLength);
314 323
 		}
315 324
 		if(!$isLastPart){
316
-			if($plainTextLength % $blocksize != 0)
317
-				throw new Ks3ClientException("Invalid part size,part size (".$plainTextLength.") must be multiples of the block size ".$blocksize);
318
-		}else{
325
+			if($plainTextLength % $blocksize != 0) {
326
+							throw new Ks3ClientException("Invalid part size,part size (".$plainTextLength.") must be multiples of the block size ".$blocksize);
327
+			}
328
+		} else{
319 329
 			$args["ObjectMeta"]["Content-Length"] = $plainTextLength + ($blocksize - $plainTextLength%$blocksize);
320 330
 		}
321 331
 		$readCallBack = new AESCBCStreamReadCallBack();
Please login to merge, or discard this patch.
src/service/ksyun/bin/encryption/EncryptionCallBack.php 3 patches
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -2,226 +2,226 @@
 block discarded – undo
2 2
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR."EncryptionUtil.php";
3 3
 //下载
4 4
 class AESCBCStreamWriteCallBack{
5
-	private $iv;
6
-	private $cek;
7
-	private $contentLength;
8
-	//数组,分别为上限和下限
9
-	private $expectedRange;
10
-	//经过调整后的range
11
-	private $adjustedRange;
12
-	//当前指针位置
13
-	private $currentIndex;
14
-	private $buffer;//上一次调用streaming_write_callback后,未解码的数据
15
-	private $firstWrite = TRUE;
16
-	public function __set($property_name, $value){
17
-		$this->$property_name=$value;
18
-	}
19
-	public function __get($property_name){
20
-		if(isset($this->$property_name))
21
-		{
22
-			return($this->$property_name);
23
-		}else
24
-		{
25
-			return(NULL);
26
-		}
27
-	}
28
-	//最后的数据大小肯定是blocksize的倍数,所以最后buffer中不会有未解密的内容。否则可以认为该文件是错误的
29
-	public function streaming_write_callback($curl_handle,$data,$write_stream){
30
-		$data = $this->buffer.$data;
5
+    private $iv;
6
+    private $cek;
7
+    private $contentLength;
8
+    //数组,分别为上限和下限
9
+    private $expectedRange;
10
+    //经过调整后的range
11
+    private $adjustedRange;
12
+    //当前指针位置
13
+    private $currentIndex;
14
+    private $buffer;//上一次调用streaming_write_callback后,未解码的数据
15
+    private $firstWrite = TRUE;
16
+    public function __set($property_name, $value){
17
+        $this->$property_name=$value;
18
+    }
19
+    public function __get($property_name){
20
+        if(isset($this->$property_name))
21
+        {
22
+            return($this->$property_name);
23
+        }else
24
+        {
25
+            return(NULL);
26
+        }
27
+    }
28
+    //最后的数据大小肯定是blocksize的倍数,所以最后buffer中不会有未解密的内容。否则可以认为该文件是错误的
29
+    public function streaming_write_callback($curl_handle,$data,$write_stream){
30
+        $data = $this->buffer.$data;
31 31
 
32
-		$length = strlen($data);
33
-		//不能把上次的没读完的长度算在这次里,应该算在上次
34
-		$written_total = 0-strlen($this->buffer);
35
-		$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
36
-		if($length<$blocksize)
37
-			$this->buffer = $data;
38
-		else{
39
-			//如果期望的范围之后还有数据,则认为数据已经接收完毕。不做任何处理
40
-			if($this->expectedRange["end"] < $this->expectedRange["start"]){
41
-				return $written_total+strlen($data);
42
-			}
43
-			$this->buffer = substr($data,$length - $length%$blocksize);
44
-			$data = substr($data,0,$length - $length%$blocksize);
32
+        $length = strlen($data);
33
+        //不能把上次的没读完的长度算在这次里,应该算在上次
34
+        $written_total = 0-strlen($this->buffer);
35
+        $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
36
+        if($length<$blocksize)
37
+            $this->buffer = $data;
38
+        else{
39
+            //如果期望的范围之后还有数据,则认为数据已经接收完毕。不做任何处理
40
+            if($this->expectedRange["end"] < $this->expectedRange["start"]){
41
+                return $written_total+strlen($data);
42
+            }
43
+            $this->buffer = substr($data,$length - $length%$blocksize);
44
+            $data = substr($data,0,$length - $length%$blocksize);
45 45
 		
46
-			$ivoffset = 0;
47
-			//range get时,如果不是从刚开始,则应该取加密后数据的前16个字节作为之后解密的iv
48
-			if($this->firstWrite){
49
-				$this->firstWrite = FALSE;
50
-				if(!$this->isBegin()){
51
-					$this->iv = substr($data,0,$blocksize);
52
-					$data = substr($data,$blocksize);
53
-					$ivoffset = $blocksize;
54
-				}
55
-				//初始化当前位置
56
-				if(isset($this->adjustedRange))
57
-					$this->currentIndex = $ivoffset+$this->adjustedRange["start"];
58
-				else
59
-					$this->currentIndex = $ivoffset;
60
-			}
61
-			$written_total+=$ivoffset;
62
-			if(strlen($data) == 0){
63
-				$decoded = "";
64
-				return $written_total;
65
-			}else{
66
-				$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
67
-				mcrypt_generic_init($td,$this->cek,$this->iv);
68
-				$decoded = mdecrypt_generic($td,$data);
69
-				mcrypt_generic_deinit($td);
70
-				mcrypt_module_close($td);
71
-			}
46
+            $ivoffset = 0;
47
+            //range get时,如果不是从刚开始,则应该取加密后数据的前16个字节作为之后解密的iv
48
+            if($this->firstWrite){
49
+                $this->firstWrite = FALSE;
50
+                if(!$this->isBegin()){
51
+                    $this->iv = substr($data,0,$blocksize);
52
+                    $data = substr($data,$blocksize);
53
+                    $ivoffset = $blocksize;
54
+                }
55
+                //初始化当前位置
56
+                if(isset($this->adjustedRange))
57
+                    $this->currentIndex = $ivoffset+$this->adjustedRange["start"];
58
+                else
59
+                    $this->currentIndex = $ivoffset;
60
+            }
61
+            $written_total+=$ivoffset;
62
+            if(strlen($data) == 0){
63
+                $decoded = "";
64
+                return $written_total;
65
+            }else{
66
+                $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
67
+                mcrypt_generic_init($td,$this->cek,$this->iv);
68
+                $decoded = mdecrypt_generic($td,$data);
69
+                mcrypt_generic_deinit($td);
70
+                mcrypt_module_close($td);
71
+            }
72 72
 
73
-			$this->iv = substr($data,strlen($data)-$blocksize);
74
-			//判断是否需要删除最后填充的字符,以及获取填充的字符
75
-			$needRemovePad = FALSE;
76
-			$pad = NULL;
73
+            $this->iv = substr($data,strlen($data)-$blocksize);
74
+            //判断是否需要删除最后填充的字符,以及获取填充的字符
75
+            $needRemovePad = FALSE;
76
+            $pad = NULL;
77 77
 
78
-			if($this->currentIndex+strlen($decoded) >=$this->contentLength){
79
-				$needRemovePad = TRUE;
80
-				$pad = ord(substr($decoded,strlen($decoded)-1,1));
81
-				if($pad<=0||$pad>$blocksize)
82
-				{
83
-					//invalid pad
84
-					$needRemovePad = FALSE;
85
-				}
86
-			}
78
+            if($this->currentIndex+strlen($decoded) >=$this->contentLength){
79
+                $needRemovePad = TRUE;
80
+                $pad = ord(substr($decoded,strlen($decoded)-1,1));
81
+                if($pad<=0||$pad>$blocksize)
82
+                {
83
+                    //invalid pad
84
+                    $needRemovePad = FALSE;
85
+                }
86
+            }
87 87
 
88
-			//将解密后的数据截取到期望的长度
89
-			$startOffset = 0;
90
-			$endOffset = 0;
91
-			if(isset($this->expectedRange)){
92
-				$trueEnd = $expectedEnd = $this->expectedRange["end"];
88
+            //将解密后的数据截取到期望的长度
89
+            $startOffset = 0;
90
+            $endOffset = 0;
91
+            if(isset($this->expectedRange)){
92
+                $trueEnd = $expectedEnd = $this->expectedRange["end"];
93 93
 
94
-				if($this->currentIndex+strlen($decoded)>$expectedEnd){
95
-					$preLength = strlen($decoded);
96
-					$decoded = substr($decoded, 0,$expectedEnd-$this->currentIndex+1);
97
-					$endOffset = $preLength-strlen($decoded);
98
-				}else{
99
-					//因为range是开始结束都计算的,range=1-2。currentIndex=1,长度是2,end=currentIndex+2-1
100
-					$trueEnd = $this->currentIndex+strlen($decoded)-1; 
101
-				}
102
-				$expectedStart = $this->expectedRange["start"];
103
-				if($this->currentIndex<$expectedStart){
104
-					$decoded = substr($decoded,$expectedStart - $this->currentIndex);
105
-					$startOffset = $expectedStart - $this->currentIndex;
106
-				}
107
-				//调整下次期望的开始
108
-				$this->expectedRange["start"] = $trueEnd+1;
109
-			}
94
+                if($this->currentIndex+strlen($decoded)>$expectedEnd){
95
+                    $preLength = strlen($decoded);
96
+                    $decoded = substr($decoded, 0,$expectedEnd-$this->currentIndex+1);
97
+                    $endOffset = $preLength-strlen($decoded);
98
+                }else{
99
+                    //因为range是开始结束都计算的,range=1-2。currentIndex=1,长度是2,end=currentIndex+2-1
100
+                    $trueEnd = $this->currentIndex+strlen($decoded)-1; 
101
+                }
102
+                $expectedStart = $this->expectedRange["start"];
103
+                if($this->currentIndex<$expectedStart){
104
+                    $decoded = substr($decoded,$expectedStart - $this->currentIndex);
105
+                    $startOffset = $expectedStart - $this->currentIndex;
106
+                }
107
+                //调整下次期望的开始
108
+                $this->expectedRange["start"] = $trueEnd+1;
109
+            }
110 110
 
111
-			$padOffset = 0;
112
-			//再次根据截取的长度判断是否需要删除最后填充的字符
113
-			if($needRemovePad&&$endOffset > $pad){
114
-				$needRemovePad = FALSE;
115
-			}
116
-			$actualWriteCount = 0;
117
-			if($needRemovePad){
118
-				$padOffset = $pad-$endOffset;
119
-				$actualWriteCount = strlen($decoded)-$padOffset;
120
-				if($actualWriteCount <= 0)//负数的情况就是用户期望的range里全是填充的
121
-					$decoded = "";
122
-				else
123
-					$decoded = substr($decoded,0,strlen($decoded)-$padOffset);
124
-			}
125
-			$count = fwrite($write_stream, $decoded);
126
-			if($count == 0)
127
-				$count = $actualWriteCount;
128
-			$count += $padOffset;
129
-			$count += $startOffset;
130
-			$count += $endOffset;
131
-			$this->currentIndex += $count;
132
-			$written_total+=$count;
133
-		}
134
-		//否则curl框架会报错
135
-		$written_total+=strlen($this->buffer);
136
-		return $written_total;
137
-	}
138
-	//是的话则使用初始化IV
139
-	private function isBegin(){
140
-		$beginIndex = 0;
141
-		if(isset($this->adjustedRange["start"]))
142
-			$beginIndex = $this->adjustedRange["start"];
143
-		if($beginIndex == 0)
144
-			return TRUE;
145
-		else 
146
-			return FALSE;
147
-	}
111
+            $padOffset = 0;
112
+            //再次根据截取的长度判断是否需要删除最后填充的字符
113
+            if($needRemovePad&&$endOffset > $pad){
114
+                $needRemovePad = FALSE;
115
+            }
116
+            $actualWriteCount = 0;
117
+            if($needRemovePad){
118
+                $padOffset = $pad-$endOffset;
119
+                $actualWriteCount = strlen($decoded)-$padOffset;
120
+                if($actualWriteCount <= 0)//负数的情况就是用户期望的range里全是填充的
121
+                    $decoded = "";
122
+                else
123
+                    $decoded = substr($decoded,0,strlen($decoded)-$padOffset);
124
+            }
125
+            $count = fwrite($write_stream, $decoded);
126
+            if($count == 0)
127
+                $count = $actualWriteCount;
128
+            $count += $padOffset;
129
+            $count += $startOffset;
130
+            $count += $endOffset;
131
+            $this->currentIndex += $count;
132
+            $written_total+=$count;
133
+        }
134
+        //否则curl框架会报错
135
+        $written_total+=strlen($this->buffer);
136
+        return $written_total;
137
+    }
138
+    //是的话则使用初始化IV
139
+    private function isBegin(){
140
+        $beginIndex = 0;
141
+        if(isset($this->adjustedRange["start"]))
142
+            $beginIndex = $this->adjustedRange["start"];
143
+        if($beginIndex == 0)
144
+            return TRUE;
145
+        else 
146
+            return FALSE;
147
+    }
148 148
 }
149 149
 //上传
150 150
 class AESCBCStreamReadCallBack{
151
-	private $iv;
152
-	private $cek;
153
-	private $contentLength;
154
-	private $buffer;
155
-	private $hasread = 0;
156
-	private $mutipartUpload =FALSE;
157
-	private $isLastPart = FALSE;
158
-	public function __set($property_name, $value){
159
-		$this->$property_name=$value;
160
-	}
161
-	public function __get($property_name){
162
-		if(isset($this->$property_name))
163
-		{
164
-			return($this->$property_name);
165
-		}else
166
-		{
167
-			return(NULL);
168
-		}
169
-	}
170
-	public function streaming_read_callback($curl_handle,$file_handle,$length,$read_stream,$seek_position){
171
-		// Once we've sent as much as we're supposed to send...
172
-		if ($this->hasread >= $this->contentLength)
173
-		{
174
-			// Send EOF
175
-			return '';
176
-		}
177
-		// If we're at the beginning of an upload and need to seek...
178
-		if ($this->hasread == 0 && $seek_position>0 && $seek_position !== ftell($read_stream))
179
-		{
180
-			if (fseek($read_stream, $seek_position) !== 0)
181
-			{
182
-				throw new RequestCore_Exception('The stream does not support seeking and is either not at the requested position or the position is unknown.');
183
-			}
184
-		}
151
+    private $iv;
152
+    private $cek;
153
+    private $contentLength;
154
+    private $buffer;
155
+    private $hasread = 0;
156
+    private $mutipartUpload =FALSE;
157
+    private $isLastPart = FALSE;
158
+    public function __set($property_name, $value){
159
+        $this->$property_name=$value;
160
+    }
161
+    public function __get($property_name){
162
+        if(isset($this->$property_name))
163
+        {
164
+            return($this->$property_name);
165
+        }else
166
+        {
167
+            return(NULL);
168
+        }
169
+    }
170
+    public function streaming_read_callback($curl_handle,$file_handle,$length,$read_stream,$seek_position){
171
+        // Once we've sent as much as we're supposed to send...
172
+        if ($this->hasread >= $this->contentLength)
173
+        {
174
+            // Send EOF
175
+            return '';
176
+        }
177
+        // If we're at the beginning of an upload and need to seek...
178
+        if ($this->hasread == 0 && $seek_position>0 && $seek_position !== ftell($read_stream))
179
+        {
180
+            if (fseek($read_stream, $seek_position) !== 0)
181
+            {
182
+                throw new RequestCore_Exception('The stream does not support seeking and is either not at the requested position or the position is unknown.');
183
+            }
184
+        }
185 185
 
186 186
 
187
-		$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_ECB);
188
-		$needRead = min($this->contentLength - $this->hasread,$length);
189
-		$read = fread($read_stream,$needRead);
190
-		$this->hasread += strlen($read);
191
-		$isLast = FALSE;
192
-		if($this->hasread >= $this->contentLength){
193
-			$isLast = TRUE;
194
-		}
195
-		$data = $this->buffer.$read;
187
+        $blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_ECB);
188
+        $needRead = min($this->contentLength - $this->hasread,$length);
189
+        $read = fread($read_stream,$needRead);
190
+        $this->hasread += strlen($read);
191
+        $isLast = FALSE;
192
+        if($this->hasread >= $this->contentLength){
193
+            $isLast = TRUE;
194
+        }
195
+        $data = $this->buffer.$read;
196 196
 
197
-		$dataLength = strlen($data);
197
+        $dataLength = strlen($data);
198 198
 
199
-		if(!$isLast){
200
-			$this->buffer = substr($data,$dataLength-$dataLength%$blocksize);
201
-			$data = substr($data, 0,$dataLength-$dataLength%$blocksize);
202
-		}else{
203
-			//分块上传除最后一块外肯定是blocksize大小的倍数,所以不需要填充。
204
-			if($this->mutipartUpload){
205
-				if($this->isLastPart){
206
-					$this->buffer = NULL;
207
-					$data = EncryptionUtil::PKCS5Padding($data,$blocksize);
208
-				}else{
209
-					//donothing
210
-				}
211
-			}else{
212
-				$this->buffer = NULL;
213
-				$data = EncryptionUtil::PKCS5Padding($data,$blocksize);
214
-			}
215
-		}
216
-		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
217
-		mcrypt_generic_init($td,$this->cek,$this->iv);
218
-		$encrypted = mcrypt_generic($td,$data);
219
-		mcrypt_generic_deinit($td);
220
-		//去除自动填充的16个字节//php的当恰好为16的倍数时竟然不填充?
221
-		//$encrypted = substr($encrypted,0,strlen($encrypted)-$blocksize);
222
-		//取最后一个block作为下一次的iv
223
-		$this->iv = substr($encrypted, strlen($encrypted)-$blocksize);
224
-		return $encrypted;
225
-	}
199
+        if(!$isLast){
200
+            $this->buffer = substr($data,$dataLength-$dataLength%$blocksize);
201
+            $data = substr($data, 0,$dataLength-$dataLength%$blocksize);
202
+        }else{
203
+            //分块上传除最后一块外肯定是blocksize大小的倍数,所以不需要填充。
204
+            if($this->mutipartUpload){
205
+                if($this->isLastPart){
206
+                    $this->buffer = NULL;
207
+                    $data = EncryptionUtil::PKCS5Padding($data,$blocksize);
208
+                }else{
209
+                    //donothing
210
+                }
211
+            }else{
212
+                $this->buffer = NULL;
213
+                $data = EncryptionUtil::PKCS5Padding($data,$blocksize);
214
+            }
215
+        }
216
+        $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
217
+        mcrypt_generic_init($td,$this->cek,$this->iv);
218
+        $encrypted = mcrypt_generic($td,$data);
219
+        mcrypt_generic_deinit($td);
220
+        //去除自动填充的16个字节//php的当恰好为16的倍数时竟然不填充?
221
+        //$encrypted = substr($encrypted,0,strlen($encrypted)-$blocksize);
222
+        //取最后一个block作为下一次的iv
223
+        $this->iv = substr($encrypted, strlen($encrypted)-$blocksize);
224
+        return $encrypted;
225
+    }
226 226
 }
227 227
 ?>
228 228
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."encryption".DIRECTORY_SEPARATOR."EncryptionUtil.php";
3 3
 //下载
4
-class AESCBCStreamWriteCallBack{
4
+class AESCBCStreamWriteCallBack {
5 5
 	private $iv;
6 6
 	private $cek;
7 7
 	private $contentLength;
@@ -11,13 +11,13 @@  discard block
 block discarded – undo
11 11
 	private $adjustedRange;
12 12
 	//当前指针位置
13 13
 	private $currentIndex;
14
-	private $buffer;//上一次调用streaming_write_callback后,未解码的数据
14
+	private $buffer; //上一次调用streaming_write_callback后,未解码的数据
15 15
 	private $firstWrite = TRUE;
16
-	public function __set($property_name, $value){
17
-		$this->$property_name=$value;
16
+	public function __set($property_name, $value) {
17
+		$this->$property_name = $value;
18 18
 	}
19
-	public function __get($property_name){
20
-		if(isset($this->$property_name))
19
+	public function __get($property_name) {
20
+		if (isset($this->$property_name))
21 21
 		{
22 22
 			return($this->$property_name);
23 23
 		}else
@@ -26,59 +26,59 @@  discard block
 block discarded – undo
26 26
 		}
27 27
 	}
28 28
 	//最后的数据大小肯定是blocksize的倍数,所以最后buffer中不会有未解密的内容。否则可以认为该文件是错误的
29
-	public function streaming_write_callback($curl_handle,$data,$write_stream){
29
+	public function streaming_write_callback($curl_handle, $data, $write_stream) {
30 30
 		$data = $this->buffer.$data;
31 31
 
32 32
 		$length = strlen($data);
33 33
 		//不能把上次的没读完的长度算在这次里,应该算在上次
34 34
 		$written_total = 0-strlen($this->buffer);
35
-		$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
36
-		if($length<$blocksize)
35
+		$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
36
+		if ($length < $blocksize)
37 37
 			$this->buffer = $data;
38
-		else{
38
+		else {
39 39
 			//如果期望的范围之后还有数据,则认为数据已经接收完毕。不做任何处理
40
-			if($this->expectedRange["end"] < $this->expectedRange["start"]){
40
+			if ($this->expectedRange["end"] < $this->expectedRange["start"]) {
41 41
 				return $written_total+strlen($data);
42 42
 			}
43
-			$this->buffer = substr($data,$length - $length%$blocksize);
44
-			$data = substr($data,0,$length - $length%$blocksize);
43
+			$this->buffer = substr($data, $length-$length%$blocksize);
44
+			$data = substr($data, 0, $length-$length%$blocksize);
45 45
 		
46 46
 			$ivoffset = 0;
47 47
 			//range get时,如果不是从刚开始,则应该取加密后数据的前16个字节作为之后解密的iv
48
-			if($this->firstWrite){
48
+			if ($this->firstWrite) {
49 49
 				$this->firstWrite = FALSE;
50
-				if(!$this->isBegin()){
51
-					$this->iv = substr($data,0,$blocksize);
52
-					$data = substr($data,$blocksize);
50
+				if (!$this->isBegin()) {
51
+					$this->iv = substr($data, 0, $blocksize);
52
+					$data = substr($data, $blocksize);
53 53
 					$ivoffset = $blocksize;
54 54
 				}
55 55
 				//初始化当前位置
56
-				if(isset($this->adjustedRange))
56
+				if (isset($this->adjustedRange))
57 57
 					$this->currentIndex = $ivoffset+$this->adjustedRange["start"];
58 58
 				else
59 59
 					$this->currentIndex = $ivoffset;
60 60
 			}
61
-			$written_total+=$ivoffset;
62
-			if(strlen($data) == 0){
61
+			$written_total += $ivoffset;
62
+			if (strlen($data) == 0) {
63 63
 				$decoded = "";
64 64
 				return $written_total;
65
-			}else{
66
-				$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
67
-				mcrypt_generic_init($td,$this->cek,$this->iv);
68
-				$decoded = mdecrypt_generic($td,$data);
65
+			}else {
66
+				$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
67
+				mcrypt_generic_init($td, $this->cek, $this->iv);
68
+				$decoded = mdecrypt_generic($td, $data);
69 69
 				mcrypt_generic_deinit($td);
70 70
 				mcrypt_module_close($td);
71 71
 			}
72 72
 
73
-			$this->iv = substr($data,strlen($data)-$blocksize);
73
+			$this->iv = substr($data, strlen($data)-$blocksize);
74 74
 			//判断是否需要删除最后填充的字符,以及获取填充的字符
75 75
 			$needRemovePad = FALSE;
76 76
 			$pad = NULL;
77 77
 
78
-			if($this->currentIndex+strlen($decoded) >=$this->contentLength){
78
+			if ($this->currentIndex+strlen($decoded) >= $this->contentLength) {
79 79
 				$needRemovePad = TRUE;
80
-				$pad = ord(substr($decoded,strlen($decoded)-1,1));
81
-				if($pad<=0||$pad>$blocksize)
80
+				$pad = ord(substr($decoded, strlen($decoded)-1, 1));
81
+				if ($pad <= 0 || $pad > $blocksize)
82 82
 				{
83 83
 					//invalid pad
84 84
 					$needRemovePad = FALSE;
@@ -88,21 +88,21 @@  discard block
 block discarded – undo
88 88
 			//将解密后的数据截取到期望的长度
89 89
 			$startOffset = 0;
90 90
 			$endOffset = 0;
91
-			if(isset($this->expectedRange)){
91
+			if (isset($this->expectedRange)) {
92 92
 				$trueEnd = $expectedEnd = $this->expectedRange["end"];
93 93
 
94
-				if($this->currentIndex+strlen($decoded)>$expectedEnd){
94
+				if ($this->currentIndex+strlen($decoded) > $expectedEnd) {
95 95
 					$preLength = strlen($decoded);
96
-					$decoded = substr($decoded, 0,$expectedEnd-$this->currentIndex+1);
96
+					$decoded = substr($decoded, 0, $expectedEnd-$this->currentIndex+1);
97 97
 					$endOffset = $preLength-strlen($decoded);
98
-				}else{
98
+				}else {
99 99
 					//因为range是开始结束都计算的,range=1-2。currentIndex=1,长度是2,end=currentIndex+2-1
100 100
 					$trueEnd = $this->currentIndex+strlen($decoded)-1; 
101 101
 				}
102 102
 				$expectedStart = $this->expectedRange["start"];
103
-				if($this->currentIndex<$expectedStart){
104
-					$decoded = substr($decoded,$expectedStart - $this->currentIndex);
105
-					$startOffset = $expectedStart - $this->currentIndex;
103
+				if ($this->currentIndex < $expectedStart) {
104
+					$decoded = substr($decoded, $expectedStart-$this->currentIndex);
105
+					$startOffset = $expectedStart-$this->currentIndex;
106 106
 				}
107 107
 				//调整下次期望的开始
108 108
 				$this->expectedRange["start"] = $trueEnd+1;
@@ -110,56 +110,56 @@  discard block
 block discarded – undo
110 110
 
111 111
 			$padOffset = 0;
112 112
 			//再次根据截取的长度判断是否需要删除最后填充的字符
113
-			if($needRemovePad&&$endOffset > $pad){
113
+			if ($needRemovePad && $endOffset > $pad) {
114 114
 				$needRemovePad = FALSE;
115 115
 			}
116 116
 			$actualWriteCount = 0;
117
-			if($needRemovePad){
117
+			if ($needRemovePad) {
118 118
 				$padOffset = $pad-$endOffset;
119 119
 				$actualWriteCount = strlen($decoded)-$padOffset;
120
-				if($actualWriteCount <= 0)//负数的情况就是用户期望的range里全是填充的
120
+				if ($actualWriteCount <= 0)//负数的情况就是用户期望的range里全是填充的
121 121
 					$decoded = "";
122 122
 				else
123
-					$decoded = substr($decoded,0,strlen($decoded)-$padOffset);
123
+					$decoded = substr($decoded, 0, strlen($decoded)-$padOffset);
124 124
 			}
125 125
 			$count = fwrite($write_stream, $decoded);
126
-			if($count == 0)
126
+			if ($count == 0)
127 127
 				$count = $actualWriteCount;
128 128
 			$count += $padOffset;
129 129
 			$count += $startOffset;
130 130
 			$count += $endOffset;
131 131
 			$this->currentIndex += $count;
132
-			$written_total+=$count;
132
+			$written_total += $count;
133 133
 		}
134 134
 		//否则curl框架会报错
135
-		$written_total+=strlen($this->buffer);
135
+		$written_total += strlen($this->buffer);
136 136
 		return $written_total;
137 137
 	}
138 138
 	//是的话则使用初始化IV
139
-	private function isBegin(){
139
+	private function isBegin() {
140 140
 		$beginIndex = 0;
141
-		if(isset($this->adjustedRange["start"]))
141
+		if (isset($this->adjustedRange["start"]))
142 142
 			$beginIndex = $this->adjustedRange["start"];
143
-		if($beginIndex == 0)
143
+		if ($beginIndex == 0)
144 144
 			return TRUE;
145 145
 		else 
146 146
 			return FALSE;
147 147
 	}
148 148
 }
149 149
 //上传
150
-class AESCBCStreamReadCallBack{
150
+class AESCBCStreamReadCallBack {
151 151
 	private $iv;
152 152
 	private $cek;
153 153
 	private $contentLength;
154 154
 	private $buffer;
155 155
 	private $hasread = 0;
156
-	private $mutipartUpload =FALSE;
156
+	private $mutipartUpload = FALSE;
157 157
 	private $isLastPart = FALSE;
158
-	public function __set($property_name, $value){
159
-		$this->$property_name=$value;
158
+	public function __set($property_name, $value) {
159
+		$this->$property_name = $value;
160 160
 	}
161
-	public function __get($property_name){
162
-		if(isset($this->$property_name))
161
+	public function __get($property_name) {
162
+		if (isset($this->$property_name))
163 163
 		{
164 164
 			return($this->$property_name);
165 165
 		}else
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 			return(NULL);
168 168
 		}
169 169
 	}
170
-	public function streaming_read_callback($curl_handle,$file_handle,$length,$read_stream,$seek_position){
170
+	public function streaming_read_callback($curl_handle, $file_handle, $length, $read_stream, $seek_position) {
171 171
 		// Once we've sent as much as we're supposed to send...
172 172
 		if ($this->hasread >= $this->contentLength)
173 173
 		{
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 			return '';
176 176
 		}
177 177
 		// If we're at the beginning of an upload and need to seek...
178
-		if ($this->hasread == 0 && $seek_position>0 && $seek_position !== ftell($read_stream))
178
+		if ($this->hasread == 0 && $seek_position > 0 && $seek_position !== ftell($read_stream))
179 179
 		{
180 180
 			if (fseek($read_stream, $seek_position) !== 0)
181 181
 			{
@@ -184,38 +184,38 @@  discard block
 block discarded – undo
184 184
 		}
185 185
 
186 186
 
187
-		$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_ECB);
188
-		$needRead = min($this->contentLength - $this->hasread,$length);
189
-		$read = fread($read_stream,$needRead);
187
+		$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
188
+		$needRead = min($this->contentLength-$this->hasread, $length);
189
+		$read = fread($read_stream, $needRead);
190 190
 		$this->hasread += strlen($read);
191 191
 		$isLast = FALSE;
192
-		if($this->hasread >= $this->contentLength){
192
+		if ($this->hasread >= $this->contentLength) {
193 193
 			$isLast = TRUE;
194 194
 		}
195 195
 		$data = $this->buffer.$read;
196 196
 
197 197
 		$dataLength = strlen($data);
198 198
 
199
-		if(!$isLast){
200
-			$this->buffer = substr($data,$dataLength-$dataLength%$blocksize);
201
-			$data = substr($data, 0,$dataLength-$dataLength%$blocksize);
202
-		}else{
199
+		if (!$isLast) {
200
+			$this->buffer = substr($data, $dataLength-$dataLength%$blocksize);
201
+			$data = substr($data, 0, $dataLength-$dataLength%$blocksize);
202
+		}else {
203 203
 			//分块上传除最后一块外肯定是blocksize大小的倍数,所以不需要填充。
204
-			if($this->mutipartUpload){
205
-				if($this->isLastPart){
204
+			if ($this->mutipartUpload) {
205
+				if ($this->isLastPart) {
206 206
 					$this->buffer = NULL;
207
-					$data = EncryptionUtil::PKCS5Padding($data,$blocksize);
208
-				}else{
207
+					$data = EncryptionUtil::PKCS5Padding($data, $blocksize);
208
+				}else {
209 209
 					//donothing
210 210
 				}
211
-			}else{
211
+			}else {
212 212
 				$this->buffer = NULL;
213
-				$data = EncryptionUtil::PKCS5Padding($data,$blocksize);
213
+				$data = EncryptionUtil::PKCS5Padding($data, $blocksize);
214 214
 			}
215 215
 		}
216
-		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
217
-		mcrypt_generic_init($td,$this->cek,$this->iv);
218
-		$encrypted = mcrypt_generic($td,$data);
216
+		$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
217
+		mcrypt_generic_init($td, $this->cek, $this->iv);
218
+		$encrypted = mcrypt_generic($td, $data);
219 219
 		mcrypt_generic_deinit($td);
220 220
 		//去除自动填充的16个字节//php的当恰好为16的倍数时竟然不填充?
221 221
 		//$encrypted = substr($encrypted,0,strlen($encrypted)-$blocksize);
Please login to merge, or discard this patch.
Braces   +31 added lines, -25 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 		if(isset($this->$property_name))
21 21
 		{
22 22
 			return($this->$property_name);
23
-		}else
23
+		} else
24 24
 		{
25 25
 			return(NULL);
26 26
 		}
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
 		//不能把上次的没读完的长度算在这次里,应该算在上次
34 34
 		$written_total = 0-strlen($this->buffer);
35 35
 		$blocksize = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC);
36
-		if($length<$blocksize)
37
-			$this->buffer = $data;
38
-		else{
36
+		if($length<$blocksize) {
37
+					$this->buffer = $data;
38
+		} else{
39 39
 			//如果期望的范围之后还有数据,则认为数据已经接收完毕。不做任何处理
40 40
 			if($this->expectedRange["end"] < $this->expectedRange["start"]){
41 41
 				return $written_total+strlen($data);
@@ -53,16 +53,17 @@  discard block
 block discarded – undo
53 53
 					$ivoffset = $blocksize;
54 54
 				}
55 55
 				//初始化当前位置
56
-				if(isset($this->adjustedRange))
57
-					$this->currentIndex = $ivoffset+$this->adjustedRange["start"];
58
-				else
59
-					$this->currentIndex = $ivoffset;
56
+				if(isset($this->adjustedRange)) {
57
+									$this->currentIndex = $ivoffset+$this->adjustedRange["start"];
58
+				} else {
59
+									$this->currentIndex = $ivoffset;
60
+				}
60 61
 			}
61 62
 			$written_total+=$ivoffset;
62 63
 			if(strlen($data) == 0){
63 64
 				$decoded = "";
64 65
 				return $written_total;
65
-			}else{
66
+			} else{
66 67
 				$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128,'',MCRYPT_MODE_CBC,'');
67 68
 				mcrypt_generic_init($td,$this->cek,$this->iv);
68 69
 				$decoded = mdecrypt_generic($td,$data);
@@ -95,7 +96,7 @@  discard block
 block discarded – undo
95 96
 					$preLength = strlen($decoded);
96 97
 					$decoded = substr($decoded, 0,$expectedEnd-$this->currentIndex+1);
97 98
 					$endOffset = $preLength-strlen($decoded);
98
-				}else{
99
+				} else{
99 100
 					//因为range是开始结束都计算的,range=1-2。currentIndex=1,长度是2,end=currentIndex+2-1
100 101
 					$trueEnd = $this->currentIndex+strlen($decoded)-1; 
101 102
 				}
@@ -117,14 +118,17 @@  discard block
 block discarded – undo
117 118
 			if($needRemovePad){
118 119
 				$padOffset = $pad-$endOffset;
119 120
 				$actualWriteCount = strlen($decoded)-$padOffset;
120
-				if($actualWriteCount <= 0)//负数的情况就是用户期望的range里全是填充的
121
+				if($actualWriteCount <= 0) {
122
+				    //负数的情况就是用户期望的range里全是填充的
121 123
 					$decoded = "";
122
-				else
123
-					$decoded = substr($decoded,0,strlen($decoded)-$padOffset);
124
+				} else {
125
+									$decoded = substr($decoded,0,strlen($decoded)-$padOffset);
126
+				}
124 127
 			}
125 128
 			$count = fwrite($write_stream, $decoded);
126
-			if($count == 0)
127
-				$count = $actualWriteCount;
129
+			if($count == 0) {
130
+							$count = $actualWriteCount;
131
+			}
128 132
 			$count += $padOffset;
129 133
 			$count += $startOffset;
130 134
 			$count += $endOffset;
@@ -138,12 +142,14 @@  discard block
 block discarded – undo
138 142
 	//是的话则使用初始化IV
139 143
 	private function isBegin(){
140 144
 		$beginIndex = 0;
141
-		if(isset($this->adjustedRange["start"]))
142
-			$beginIndex = $this->adjustedRange["start"];
143
-		if($beginIndex == 0)
144
-			return TRUE;
145
-		else 
146
-			return FALSE;
145
+		if(isset($this->adjustedRange["start"])) {
146
+					$beginIndex = $this->adjustedRange["start"];
147
+		}
148
+		if($beginIndex == 0) {
149
+					return TRUE;
150
+		} else {
151
+					return FALSE;
152
+		}
147 153
 	}
148 154
 }
149 155
 //上传
@@ -162,7 +168,7 @@  discard block
 block discarded – undo
162 168
 		if(isset($this->$property_name))
163 169
 		{
164 170
 			return($this->$property_name);
165
-		}else
171
+		} else
166 172
 		{
167 173
 			return(NULL);
168 174
 		}
@@ -199,16 +205,16 @@  discard block
 block discarded – undo
199 205
 		if(!$isLast){
200 206
 			$this->buffer = substr($data,$dataLength-$dataLength%$blocksize);
201 207
 			$data = substr($data, 0,$dataLength-$dataLength%$blocksize);
202
-		}else{
208
+		} else{
203 209
 			//分块上传除最后一块外肯定是blocksize大小的倍数,所以不需要填充。
204 210
 			if($this->mutipartUpload){
205 211
 				if($this->isLastPart){
206 212
 					$this->buffer = NULL;
207 213
 					$data = EncryptionUtil::PKCS5Padding($data,$blocksize);
208
-				}else{
214
+				} else{
209 215
 					//donothing
210 216
 				}
211
-			}else{
217
+			} else{
212 218
 				$this->buffer = NULL;
213 219
 				$data = EncryptionUtil::PKCS5Padding($data,$blocksize);
214 220
 			}
Please login to merge, or discard this patch.
src/service/ksyun/bin/Ks3Client.class.php 3 patches
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -39,41 +39,41 @@  discard block
 block discarded – undo
39 39
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php";
40 40
 
41 41
 if(function_exists('get_loaded_extensions')){
42
-	//检测curl扩展
43
-	$extensions = get_loaded_extensions();
44
-	if($extensions){
45
-		if(!in_array('curl', $extensions)){
46
-			throw new Ks3ClientException("please install curl extension");
47
-		}
48
-		if(!in_array('mbstring', $extensions)){
49
-			throw new Ks3ClientException("please install mbstring extension");
42
+    //检测curl扩展
43
+    $extensions = get_loaded_extensions();
44
+    if($extensions){
45
+        if(!in_array('curl', $extensions)){
46
+            throw new Ks3ClientException("please install curl extension");
47
+        }
48
+        if(!in_array('mbstring', $extensions)){
49
+            throw new Ks3ClientException("please install mbstring extension");
50 50
 			
51
-		}
52
-	}else{
53
-		throw new Ks3ClientException("please install extensions");
54
-	}
51
+        }
52
+    }else{
53
+        throw new Ks3ClientException("please install extensions");
54
+    }
55 55
 }else{
56
-	throw new Ks3ClientException();
56
+    throw new Ks3ClientException();
57 57
 }
58 58
 
59 59
 class Ks3Client{
60
-	private $accessKey;
61
-	private $secretKey;
62
-	private $endpoint;
63
-	private $log;
64
-	public function __construct($accessKey = NULL, $secretKey = NULL, $endpoint = NULL ){
65
-		$this->accessKey = $accessKey;
66
-		$this->secretKey = $secretKey;
60
+    private $accessKey;
61
+    private $secretKey;
62
+    private $endpoint;
63
+    private $log;
64
+    public function __construct($accessKey = NULL, $secretKey = NULL, $endpoint = NULL ){
65
+        $this->accessKey = $accessKey;
66
+        $this->secretKey = $secretKey;
67 67
 
68
-		if(empty($endpoint)){
69
-			throw new Ks3ClientException("must set endpoint, please see http://ks3.ksyun.com/doc/api/index.html Region part");
70
-		}
71
-		$this->endpoint = $endpoint;
68
+        if(empty($endpoint)){
69
+            throw new Ks3ClientException("must set endpoint, please see http://ks3.ksyun.com/doc/api/index.html Region part");
70
+        }
71
+        $this->endpoint = $endpoint;
72 72
 
73
-		$this->signers = array();
74
-		$this->log = new Logger();
75
-	}
76
-	/**
73
+        $this->signers = array();
74
+        $this->log = new Logger();
75
+    }
76
+    /**
77 77
 	方法列表:(具体使用请参考readme.md)
78 78
 	listBuckets,罗列bucket
79 79
 	deleteBucket,删除bucket
@@ -107,264 +107,264 @@  discard block
 block discarded – undo
107 107
 	generatePresignedUrl,生成文件外链
108 108
 	putAdp,添加异步数据处理任务
109 109
 	getAdp,查询异步数据处理任务
110
-	*/
111
-	public function __call($method,$args=array()){
112
-		$holder = new MessageHolder();
110
+     */
111
+    public function __call($method,$args=array()){
112
+        $holder = new MessageHolder();
113 113
 
114
-		$holder->msg = "------------------Logging Start-------------------------\r\n";
115
-		$holder->msg .= "method->".$method." args->".serialize($args)."\r\n";
116
-		$ex = NULL;
117
-		try{
118
-			$result = $this->invoke($method,$args,$holder);
119
-		}catch(Exception $e){
120
-			$holder->msg.=$e."\r\n";
121
-			$ex = $e;
122
-		}
123
-		$holder->msg .= "------------------Logging End-------------------------\r\n";
124
-		$this->log->info($holder->msg);
125
-		if($ex !=NULL)
126
-			throw $ex;
127
-		return $result;
128
-	}
129
-	private function invoke($method,$args=array(),$holder,$location=NULL){
130
-		$api = API::$API[$method];
131
-		if(!$api){
132
-			throw new Ks3ClientException($method." Not Found API");
133
-		}
134
-		if(count($args) !== 0){
135
-			if(count($args)>1||!is_array($args[0])){
136
-				throw new Ks3ClientException("this method only needs one array argument");
137
-			}
138
-			$args = $args[0];
139
-		}
140
-		if(isset($api["redirect"])){
141
-			$api = API::$API[$api["redirect"]];
142
-		}
143
-		$request = new Ks3Request();
144
-		if(empty($args["Bucket"])){
145
-			if($api["needBucket"]){
146
-				throw new Ks3ClientException($method." this api need bucket");
147
-			}
148
-		}else{
149
-			$request->bucket = $args["Bucket"];
150
-		}
151
-		$position = "Key";
152
-		//position主要为queryadp接口用的
153
-		if(isset($api["objectPostion"])){
154
-			$position = $api["objectPostion"];
155
-		}
156
-		if(empty($args[$position])){
157
-			if($api["needObject"]){
158
-				throw new Ks3ClientException($method." this api need ".$position);
159
-			}
160
-		}else{
161
-			$key = $args[$position];
162
-			$preEncoding = mb_detect_encoding($key, array("ASCII","UTF-8","GB2312","GBK","BIG5"));
163
-			$holder->msg.="key encoding ".$preEncoding."\r\n";
164
-			if(strtolower($preEncoding) != "utf-8"){
165
-				$key = iconv($preEncoding, "UTF-8",$key);
166
-			}
167
-			$request->key = $key;
168
-		}
169
-		$method = $api["method"];
170
-		if($method == "Method"){
171
-			if(empty($args["Method"])){
172
-				$request->method="GET";
173
-			}else{
174
-				$request->method=$args["Method"];
175
-			}
176
-		}else{
177
-			$request->method=$api["method"];
178
-		}
179
-		if(KS3_API_USE_HTTPS)
180
-			$request->scheme="https://";
181
-		else
182
-			$request->scheme="http://";
183
-		$request->endpoint=$this->endpoint;
184
-		//add subresource
185
-		if(!empty($api["subResource"])){
186
-			$request->subResource=$api["subResource"];
187
-		}
188
-		//add query params
189
-		if(isset($api["queryParams"] )){ 
190
-			foreach ($api["queryParams"] as $key => $value) {
191
-				$required = FALSE;
192
-				if(substr($value,0,1)==="!"){
193
-					$required = TRUE;
194
-					$value=substr($value,1);
195
-				}
196
-				$index = explode("->",$value);
197
-				$curIndexArg = $args;
198
-				$add = TRUE;
199
-				$curkey = "";
200
-				foreach ($index as $key1 => $value1) {
201
-					if(!isset($curIndexArg[$value1])&&$value1 !== "*"){
202
-						$add = FALSE;
203
-					}else{
204
-						$curkey = $value1;
205
-						//星号表示所有,按照暂时的业务,默认星号后面就没了
206
-						if($curkey == "*"){
207
-							foreach ($curIndexArg as $queryK => $queryV) {
208
-								if(!is_array($queryV)){
209
-									$request->addQueryParams($queryK,$queryV);
210
-								}
211
-							}
212
-							$add = FALSE;
213
-							$required = FALSE;
214
-							break;
215
-						}else{
216
-							$curIndexArg = $curIndexArg[$value1];
217
-						}
218
-					}
219
-				}
220
-				if(!empty($curIndexArg)&&$add){
221
-					$request->addQueryParams($curkey,$curIndexArg);
222
-					continue;
223
-				}
224
-				if($required)
225
-					throw new Ks3ClientException($method." param ".$value." is required");
226
-			}
227
-		}
228
-		if(isset($api["body"])){
229
-			if(isset($api["body"]["builder"])){
230
-				$builderName = $api["body"]["builder"];
231
-				$builder = new $builderName();
232
-				$request->body = $builder->build($args);
233
-			}else if(isset($api["body"]["position"])){
234
-				$position = $api["body"]["position"];
235
-				$index = explode("->",$position);
236
-				$curIndexArg = $args;
237
-				$add = TRUE;
238
-				$curkey = "";
239
-				foreach ($index as $key1 => $value1) {
240
-					if(!isset($curIndexArg[$value1])){
241
-						$add = FALSE;
242
-					}else{
243
-						$curIndexArg = $curIndexArg[$value1];
244
-						$curkey = $value1;
245
-					}
246
-				}
247
-				if(!empty($curIndexArg)&&$add){
248
-					$request->body=$curIndexArg;
249
-				}
250
-			}
251
-		}
114
+        $holder->msg = "------------------Logging Start-------------------------\r\n";
115
+        $holder->msg .= "method->".$method." args->".serialize($args)."\r\n";
116
+        $ex = NULL;
117
+        try{
118
+            $result = $this->invoke($method,$args,$holder);
119
+        }catch(Exception $e){
120
+            $holder->msg.=$e."\r\n";
121
+            $ex = $e;
122
+        }
123
+        $holder->msg .= "------------------Logging End-------------------------\r\n";
124
+        $this->log->info($holder->msg);
125
+        if($ex !=NULL)
126
+            throw $ex;
127
+        return $result;
128
+    }
129
+    private function invoke($method,$args=array(),$holder,$location=NULL){
130
+        $api = API::$API[$method];
131
+        if(!$api){
132
+            throw new Ks3ClientException($method." Not Found API");
133
+        }
134
+        if(count($args) !== 0){
135
+            if(count($args)>1||!is_array($args[0])){
136
+                throw new Ks3ClientException("this method only needs one array argument");
137
+            }
138
+            $args = $args[0];
139
+        }
140
+        if(isset($api["redirect"])){
141
+            $api = API::$API[$api["redirect"]];
142
+        }
143
+        $request = new Ks3Request();
144
+        if(empty($args["Bucket"])){
145
+            if($api["needBucket"]){
146
+                throw new Ks3ClientException($method." this api need bucket");
147
+            }
148
+        }else{
149
+            $request->bucket = $args["Bucket"];
150
+        }
151
+        $position = "Key";
152
+        //position主要为queryadp接口用的
153
+        if(isset($api["objectPostion"])){
154
+            $position = $api["objectPostion"];
155
+        }
156
+        if(empty($args[$position])){
157
+            if($api["needObject"]){
158
+                throw new Ks3ClientException($method." this api need ".$position);
159
+            }
160
+        }else{
161
+            $key = $args[$position];
162
+            $preEncoding = mb_detect_encoding($key, array("ASCII","UTF-8","GB2312","GBK","BIG5"));
163
+            $holder->msg.="key encoding ".$preEncoding."\r\n";
164
+            if(strtolower($preEncoding) != "utf-8"){
165
+                $key = iconv($preEncoding, "UTF-8",$key);
166
+            }
167
+            $request->key = $key;
168
+        }
169
+        $method = $api["method"];
170
+        if($method == "Method"){
171
+            if(empty($args["Method"])){
172
+                $request->method="GET";
173
+            }else{
174
+                $request->method=$args["Method"];
175
+            }
176
+        }else{
177
+            $request->method=$api["method"];
178
+        }
179
+        if(KS3_API_USE_HTTPS)
180
+            $request->scheme="https://";
181
+        else
182
+            $request->scheme="http://";
183
+        $request->endpoint=$this->endpoint;
184
+        //add subresource
185
+        if(!empty($api["subResource"])){
186
+            $request->subResource=$api["subResource"];
187
+        }
188
+        //add query params
189
+        if(isset($api["queryParams"] )){ 
190
+            foreach ($api["queryParams"] as $key => $value) {
191
+                $required = FALSE;
192
+                if(substr($value,0,1)==="!"){
193
+                    $required = TRUE;
194
+                    $value=substr($value,1);
195
+                }
196
+                $index = explode("->",$value);
197
+                $curIndexArg = $args;
198
+                $add = TRUE;
199
+                $curkey = "";
200
+                foreach ($index as $key1 => $value1) {
201
+                    if(!isset($curIndexArg[$value1])&&$value1 !== "*"){
202
+                        $add = FALSE;
203
+                    }else{
204
+                        $curkey = $value1;
205
+                        //星号表示所有,按照暂时的业务,默认星号后面就没了
206
+                        if($curkey == "*"){
207
+                            foreach ($curIndexArg as $queryK => $queryV) {
208
+                                if(!is_array($queryV)){
209
+                                    $request->addQueryParams($queryK,$queryV);
210
+                                }
211
+                            }
212
+                            $add = FALSE;
213
+                            $required = FALSE;
214
+                            break;
215
+                        }else{
216
+                            $curIndexArg = $curIndexArg[$value1];
217
+                        }
218
+                    }
219
+                }
220
+                if(!empty($curIndexArg)&&$add){
221
+                    $request->addQueryParams($curkey,$curIndexArg);
222
+                    continue;
223
+                }
224
+                if($required)
225
+                    throw new Ks3ClientException($method." param ".$value." is required");
226
+            }
227
+        }
228
+        if(isset($api["body"])){
229
+            if(isset($api["body"]["builder"])){
230
+                $builderName = $api["body"]["builder"];
231
+                $builder = new $builderName();
232
+                $request->body = $builder->build($args);
233
+            }else if(isset($api["body"]["position"])){
234
+                $position = $api["body"]["position"];
235
+                $index = explode("->",$position);
236
+                $curIndexArg = $args;
237
+                $add = TRUE;
238
+                $curkey = "";
239
+                foreach ($index as $key1 => $value1) {
240
+                    if(!isset($curIndexArg[$value1])){
241
+                        $add = FALSE;
242
+                    }else{
243
+                        $curIndexArg = $curIndexArg[$value1];
244
+                        $curkey = $value1;
245
+                    }
246
+                }
247
+                if(!empty($curIndexArg)&&$add){
248
+                    $request->body=$curIndexArg;
249
+                }
250
+            }
251
+        }
252 252
 		
253
-		//add ext headers
254
-		//TODO
255
-		//sign request
256
-		$signer = NULL;
257
-		if(isset($api["signer"])){
258
-			$signers = explode("->",$api["signer"]);
259
-			foreach ($signers as $key => $value) {
260
-				$signer = new $value();
261
-				$log = $signer->sign($request,array("accessKey"=>$this->accessKey,"secretKey"=>$this->secretKey,"args"=>$args));
262
-				if(!empty($log)){
263
-					$holder->msg.=$log."\r\n";
264
-				}
265
-			}
266
-		}
253
+        //add ext headers
254
+        //TODO
255
+        //sign request
256
+        $signer = NULL;
257
+        if(isset($api["signer"])){
258
+            $signers = explode("->",$api["signer"]);
259
+            foreach ($signers as $key => $value) {
260
+                $signer = new $value();
261
+                $log = $signer->sign($request,array("accessKey"=>$this->accessKey,"secretKey"=>$this->secretKey,"args"=>$args));
262
+                if(!empty($log)){
263
+                    $holder->msg.=$log."\r\n";
264
+                }
265
+            }
266
+        }
267 267
 
268
-		if($signer===NULL||!($signer instanceof QueryAuthSigner)){
269
-			$url = $request->toUrl($this->endpoint);
270
-			if($location!=NULL)
271
-				$url = $location;
272
-			$httpRequest = new RequestCore($url);
273
-			if(KS3_API_DEBUG_MODE===TRUE)
274
-				$httpRequest->debug_mode=TRUE;
275
-			$httpRequest->set_method($request->method);
276
-			foreach ($request->headers as $key => $value) {
277
-				$httpRequest->add_header($key,$value);
278
-			}
279
-			$httpRequest->request_body=$request->body;
268
+        if($signer===NULL||!($signer instanceof QueryAuthSigner)){
269
+            $url = $request->toUrl($this->endpoint);
270
+            if($location!=NULL)
271
+                $url = $location;
272
+            $httpRequest = new RequestCore($url);
273
+            if(KS3_API_DEBUG_MODE===TRUE)
274
+                $httpRequest->debug_mode=TRUE;
275
+            $httpRequest->set_method($request->method);
276
+            foreach ($request->headers as $key => $value) {
277
+                $httpRequest->add_header($key,$value);
278
+            }
279
+            $httpRequest->request_body=$request->body;
280 280
 
281
-			if(isset($args["writeCallBack"])){
282
-				$httpRequest->register_streaming_write_callback($args["writeCallBack"]);
283
-			}
284
-			if(isset($args["readCallBack"])){
285
-				$httpRequest->register_streaming_read_callback($args["readCallBack"]);
286
-			}
281
+            if(isset($args["writeCallBack"])){
282
+                $httpRequest->register_streaming_write_callback($args["writeCallBack"]);
283
+            }
284
+            if(isset($args["readCallBack"])){
285
+                $httpRequest->register_streaming_read_callback($args["readCallBack"]);
286
+            }
287 287
 
288
-			$read_stream = $request->read_stream;
289
-			$read_length = $request->getHeader(Headers::$ContentLength);
290
-			$seek_position = $request->seek_position;
291
-			if(isset($read_stream))
292
-			{
293
-				$httpRequest->set_read_stream($read_stream,$read_length);
294
-				$httpRequest->set_seek_position($seek_position);
295
-				$httpRequest->remove_header(Headers::$ContentLength);
296
-			}
297
-			$write_stream = $request->write_stream;
298
-			if(isset($write_stream)){
299
-				$httpRequest->set_write_stream($write_stream);
300
-			}
288
+            $read_stream = $request->read_stream;
289
+            $read_length = $request->getHeader(Headers::$ContentLength);
290
+            $seek_position = $request->seek_position;
291
+            if(isset($read_stream))
292
+            {
293
+                $httpRequest->set_read_stream($read_stream,$read_length);
294
+                $httpRequest->set_seek_position($seek_position);
295
+                $httpRequest->remove_header(Headers::$ContentLength);
296
+            }
297
+            $write_stream = $request->write_stream;
298
+            if(isset($write_stream)){
299
+                $httpRequest->set_write_stream($write_stream);
300
+            }
301 301
 
302
-			$holder->msg.="request url->".serialize($httpRequest->request_url)."\r\n";
303
-			$holder->msg.="request headers->".serialize($httpRequest->request_headers)."\r\n";
304
-			$holder->msg.="request body->".$httpRequest->request_body."\r\n";
305
-			$holder->msg.="request read stream length->".$read_length."\r\n";
306
-			$holder->msg.="request read stream seek position->".$seek_position."\r\n";
307
-			$httpRequest->send_request();
308
-			//print_r($httpRequest);
309
-			$body = $httpRequest->get_response_body ();	
310
-			$data =  new ResponseCore ( $httpRequest->get_response_header() , Utils::replaceNS2($body), $httpRequest->get_response_code () );
302
+            $holder->msg.="request url->".serialize($httpRequest->request_url)."\r\n";
303
+            $holder->msg.="request headers->".serialize($httpRequest->request_headers)."\r\n";
304
+            $holder->msg.="request body->".$httpRequest->request_body."\r\n";
305
+            $holder->msg.="request read stream length->".$read_length."\r\n";
306
+            $holder->msg.="request read stream seek position->".$seek_position."\r\n";
307
+            $httpRequest->send_request();
308
+            //print_r($httpRequest);
309
+            $body = $httpRequest->get_response_body ();	
310
+            $data =  new ResponseCore ( $httpRequest->get_response_header() , Utils::replaceNS2($body), $httpRequest->get_response_code () );
311 311
 
312
-			if($data->status == 307){
313
-				$respHeaders = $httpRequest->get_response_header();
314
-				$location = $respHeaders["location"];
315
-				if(substr($location,0,4) == "http"){
316
-					$holder->msg.="response code->".$httpRequest->get_response_code ()."\r\n";
317
-					$holder->msg.="response headers->".serialize($httpRequest->get_response_header())."\r\n";
318
-					$holder->msg.="response body->".$body."\r\n";
319
-					$holder->msg.="retry request to ".$location."\r\n";
320
-					//array($args)详见invoke开头
321
-					return $this->invoke($method,array($args),$holder,$location);
322
-				}
323
-			}
324
-			$holder->msg.="response code->".$httpRequest->get_response_code ()."\r\n";
325
-			$holder->msg.="response headers->".serialize($httpRequest->get_response_header())."\r\n";
326
-			$holder->msg.="response body->".$body."\r\n";
327
-			$handlers = explode("->",$api["handler"]);
328
-			foreach ($handlers as $key => $value) {
329
-				$handler = new $value();
330
-				$data = $handler->handle($data);
331
-			}
332
-			return $data;
333
-		}else{
334
-			$url = $request->toUrl($this->endpoint);
335
-			$holder->msg.=$url."\r\n";
336
-			return $url;
337
-		}
338
-	}
339
-	//用于生产表单上传时的签名信息
340
-	public function postObject($bucket ,$postFormData=array(),$unknowValueFormFiled=array(),$filename=NULL,$expire=18000){
341
-		$policy = array();
312
+            if($data->status == 307){
313
+                $respHeaders = $httpRequest->get_response_header();
314
+                $location = $respHeaders["location"];
315
+                if(substr($location,0,4) == "http"){
316
+                    $holder->msg.="response code->".$httpRequest->get_response_code ()."\r\n";
317
+                    $holder->msg.="response headers->".serialize($httpRequest->get_response_header())."\r\n";
318
+                    $holder->msg.="response body->".$body."\r\n";
319
+                    $holder->msg.="retry request to ".$location."\r\n";
320
+                    //array($args)详见invoke开头
321
+                    return $this->invoke($method,array($args),$holder,$location);
322
+                }
323
+            }
324
+            $holder->msg.="response code->".$httpRequest->get_response_code ()."\r\n";
325
+            $holder->msg.="response headers->".serialize($httpRequest->get_response_header())."\r\n";
326
+            $holder->msg.="response body->".$body."\r\n";
327
+            $handlers = explode("->",$api["handler"]);
328
+            foreach ($handlers as $key => $value) {
329
+                $handler = new $value();
330
+                $data = $handler->handle($data);
331
+            }
332
+            return $data;
333
+        }else{
334
+            $url = $request->toUrl($this->endpoint);
335
+            $holder->msg.=$url."\r\n";
336
+            return $url;
337
+        }
338
+    }
339
+    //用于生产表单上传时的签名信息
340
+    public function postObject($bucket ,$postFormData=array(),$unknowValueFormFiled=array(),$filename=NULL,$expire=18000){
341
+        $policy = array();
342 342
 
343
-		$expireTime = Utils::iso8601(time()+$expire);
344
-		$policy["expiration"] = $expireTime;
345
-		$postFormData["bucket"]=$bucket;
346
-		$conditions = array();
347
-		foreach ($postFormData as $key => $value) {
348
-			$condition = array();
349
-			$condition[$key] = str_replace("\${filename}",$filename, $value);
350
-			array_push($conditions,$condition);
351
-		}
352
-		foreach ($unknowValueFormFiled as $key => $value) {
353
-			$condition = array();
354
-			array_push($condition,"starts-with");
355
-			array_push($condition,"\$".$value);
356
-			array_push($condition,"");
357
-			array_push($conditions,$condition);
358
-		}
359
-		$policy["conditions"] = $conditions;
360
-		$json = json_encode($policy);
361
-		$signature = base64_encode(hash_hmac('sha1', base64_encode($json), $this->secretKey, true));
362
-		$result = array();
363
-		$result["Policy"] = base64_encode($json);
364
-		$result["Signature"] = $signature;
365
-		$result["KSSAccessKeyId"] = $this->accessKey;
366
-		return $result;
367
-	}
343
+        $expireTime = Utils::iso8601(time()+$expire);
344
+        $policy["expiration"] = $expireTime;
345
+        $postFormData["bucket"]=$bucket;
346
+        $conditions = array();
347
+        foreach ($postFormData as $key => $value) {
348
+            $condition = array();
349
+            $condition[$key] = str_replace("\${filename}",$filename, $value);
350
+            array_push($conditions,$condition);
351
+        }
352
+        foreach ($unknowValueFormFiled as $key => $value) {
353
+            $condition = array();
354
+            array_push($condition,"starts-with");
355
+            array_push($condition,"\$".$value);
356
+            array_push($condition,"");
357
+            array_push($conditions,$condition);
358
+        }
359
+        $policy["conditions"] = $conditions;
360
+        $json = json_encode($policy);
361
+        $signature = base64_encode(hash_hmac('sha1', base64_encode($json), $this->secretKey, true));
362
+        $result = array();
363
+        $result["Policy"] = base64_encode($json);
364
+        $result["Signature"] = $signature;
365
+        $result["KSSAccessKeyId"] = $this->accessKey;
366
+        return $result;
367
+    }
368 368
 }
369 369
 
370 370
 ?>
Please login to merge, or discard this patch.
Spacing   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -4,28 +4,28 @@  discard block
 block discarded – undo
4 4
 date_default_timezone_set('Asia/Shanghai');
5 5
 
6 6
 //检测API路径
7
-if(!defined("KS3_API_PATH"))
7
+if (!defined("KS3_API_PATH"))
8 8
 define("KS3_API_PATH", dirname(__FILE__));
9 9
 //是否使用VHOST
10
-if(!defined("KS3_API_VHOST"))
11
-define("KS3_API_VHOST",TRUE);
10
+if (!defined("KS3_API_VHOST"))
11
+define("KS3_API_VHOST", TRUE);
12 12
 //是否开启日志(写入日志文件)
13
-if(!defined("KS3_API_LOG"))
14
-define("KS3_API_LOG",TRUE);
13
+if (!defined("KS3_API_LOG"))
14
+define("KS3_API_LOG", TRUE);
15 15
 //是否显示日志(直接输出日志)
16
-if(!defined("KS3_API_DISPLAY_LOG"))
16
+if (!defined("KS3_API_DISPLAY_LOG"))
17 17
 define("KS3_API_DISPLAY_LOG", TRUE);
18 18
 //定义日志目录(默认是该项目log下)
19
-if(!defined("KS3_API_LOG_PATH"))
20
-define("KS3_API_LOG_PATH","");
19
+if (!defined("KS3_API_LOG_PATH"))
20
+define("KS3_API_LOG_PATH", "");
21 21
 //是否使用HTTPS
22
-if(!defined("KS3_API_USE_HTTPS"))
23
-define("KS3_API_USE_HTTPS",FALSE);
22
+if (!defined("KS3_API_USE_HTTPS"))
23
+define("KS3_API_USE_HTTPS", FALSE);
24 24
 //是否开启curl debug模式
25
-if(!defined("KS3_API_DEBUG_MODE"))
26
-define("KS3_API_DEBUG_MODE",FALSE);
27
-define("KS3_API_Author","[email protected]");
28
-define("KS3_API_Version","1.2");
25
+if (!defined("KS3_API_DEBUG_MODE"))
26
+define("KS3_API_DEBUG_MODE", FALSE);
27
+define("KS3_API_Author", "[email protected]");
28
+define("KS3_API_Version", "1.2");
29 29
 
30 30
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."config".DIRECTORY_SEPARATOR."Consts.php";
31 31
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."core".DIRECTORY_SEPARATOR."API.php";
@@ -38,34 +38,34 @@  discard block
 block discarded – undo
38 38
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR."RequestCore.class.php";
39 39
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."exceptions".DIRECTORY_SEPARATOR."Exceptions.php";
40 40
 
41
-if(function_exists('get_loaded_extensions')){
41
+if (function_exists('get_loaded_extensions')) {
42 42
 	//检测curl扩展
43 43
 	$extensions = get_loaded_extensions();
44
-	if($extensions){
45
-		if(!in_array('curl', $extensions)){
44
+	if ($extensions) {
45
+		if (!in_array('curl', $extensions)) {
46 46
 			throw new Ks3ClientException("please install curl extension");
47 47
 		}
48
-		if(!in_array('mbstring', $extensions)){
48
+		if (!in_array('mbstring', $extensions)) {
49 49
 			throw new Ks3ClientException("please install mbstring extension");
50 50
 			
51 51
 		}
52
-	}else{
52
+	}else {
53 53
 		throw new Ks3ClientException("please install extensions");
54 54
 	}
55
-}else{
55
+}else {
56 56
 	throw new Ks3ClientException();
57 57
 }
58 58
 
59
-class Ks3Client{
59
+class Ks3Client {
60 60
 	private $accessKey;
61 61
 	private $secretKey;
62 62
 	private $endpoint;
63 63
 	private $log;
64
-	public function __construct($accessKey = NULL, $secretKey = NULL, $endpoint = NULL ){
64
+	public function __construct($accessKey = NULL, $secretKey = NULL, $endpoint = NULL) {
65 65
 		$this->accessKey = $accessKey;
66 66
 		$this->secretKey = $secretKey;
67 67
 
68
-		if(empty($endpoint)){
68
+		if (empty($endpoint)) {
69 69
 			throw new Ks3ClientException("must set endpoint, please see http://ks3.ksyun.com/doc/api/index.html Region part");
70 70
 		}
71 71
 		$this->endpoint = $endpoint;
@@ -108,144 +108,144 @@  discard block
 block discarded – undo
108 108
 	putAdp,添加异步数据处理任务
109 109
 	getAdp,查询异步数据处理任务
110 110
 	*/
111
-	public function __call($method,$args=array()){
111
+	public function __call($method, $args = array()) {
112 112
 		$holder = new MessageHolder();
113 113
 
114 114
 		$holder->msg = "------------------Logging Start-------------------------\r\n";
115 115
 		$holder->msg .= "method->".$method." args->".serialize($args)."\r\n";
116 116
 		$ex = NULL;
117
-		try{
118
-			$result = $this->invoke($method,$args,$holder);
119
-		}catch(Exception $e){
120
-			$holder->msg.=$e."\r\n";
117
+		try {
118
+			$result = $this->invoke($method, $args, $holder);
119
+		} catch (Exception $e) {
120
+			$holder->msg .= $e."\r\n";
121 121
 			$ex = $e;
122 122
 		}
123 123
 		$holder->msg .= "------------------Logging End-------------------------\r\n";
124 124
 		$this->log->info($holder->msg);
125
-		if($ex !=NULL)
125
+		if ($ex != NULL)
126 126
 			throw $ex;
127 127
 		return $result;
128 128
 	}
129
-	private function invoke($method,$args=array(),$holder,$location=NULL){
129
+	private function invoke($method, $args = array(), $holder, $location = NULL) {
130 130
 		$api = API::$API[$method];
131
-		if(!$api){
131
+		if (!$api) {
132 132
 			throw new Ks3ClientException($method." Not Found API");
133 133
 		}
134
-		if(count($args) !== 0){
135
-			if(count($args)>1||!is_array($args[0])){
134
+		if (count($args) !== 0) {
135
+			if (count($args) > 1 || !is_array($args[0])) {
136 136
 				throw new Ks3ClientException("this method only needs one array argument");
137 137
 			}
138 138
 			$args = $args[0];
139 139
 		}
140
-		if(isset($api["redirect"])){
140
+		if (isset($api["redirect"])) {
141 141
 			$api = API::$API[$api["redirect"]];
142 142
 		}
143 143
 		$request = new Ks3Request();
144
-		if(empty($args["Bucket"])){
145
-			if($api["needBucket"]){
144
+		if (empty($args["Bucket"])) {
145
+			if ($api["needBucket"]) {
146 146
 				throw new Ks3ClientException($method." this api need bucket");
147 147
 			}
148
-		}else{
148
+		}else {
149 149
 			$request->bucket = $args["Bucket"];
150 150
 		}
151 151
 		$position = "Key";
152 152
 		//position主要为queryadp接口用的
153
-		if(isset($api["objectPostion"])){
153
+		if (isset($api["objectPostion"])) {
154 154
 			$position = $api["objectPostion"];
155 155
 		}
156
-		if(empty($args[$position])){
157
-			if($api["needObject"]){
156
+		if (empty($args[$position])) {
157
+			if ($api["needObject"]) {
158 158
 				throw new Ks3ClientException($method." this api need ".$position);
159 159
 			}
160
-		}else{
160
+		}else {
161 161
 			$key = $args[$position];
162
-			$preEncoding = mb_detect_encoding($key, array("ASCII","UTF-8","GB2312","GBK","BIG5"));
163
-			$holder->msg.="key encoding ".$preEncoding."\r\n";
164
-			if(strtolower($preEncoding) != "utf-8"){
165
-				$key = iconv($preEncoding, "UTF-8",$key);
162
+			$preEncoding = mb_detect_encoding($key, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5"));
163
+			$holder->msg .= "key encoding ".$preEncoding."\r\n";
164
+			if (strtolower($preEncoding) != "utf-8") {
165
+				$key = iconv($preEncoding, "UTF-8", $key);
166 166
 			}
167 167
 			$request->key = $key;
168 168
 		}
169 169
 		$method = $api["method"];
170
-		if($method == "Method"){
171
-			if(empty($args["Method"])){
172
-				$request->method="GET";
173
-			}else{
174
-				$request->method=$args["Method"];
170
+		if ($method == "Method") {
171
+			if (empty($args["Method"])) {
172
+				$request->method = "GET";
173
+			}else {
174
+				$request->method = $args["Method"];
175 175
 			}
176
-		}else{
177
-			$request->method=$api["method"];
176
+		}else {
177
+			$request->method = $api["method"];
178 178
 		}
179
-		if(KS3_API_USE_HTTPS)
180
-			$request->scheme="https://";
179
+		if (KS3_API_USE_HTTPS)
180
+			$request->scheme = "https://";
181 181
 		else
182
-			$request->scheme="http://";
183
-		$request->endpoint=$this->endpoint;
182
+			$request->scheme = "http://";
183
+		$request->endpoint = $this->endpoint;
184 184
 		//add subresource
185
-		if(!empty($api["subResource"])){
186
-			$request->subResource=$api["subResource"];
185
+		if (!empty($api["subResource"])) {
186
+			$request->subResource = $api["subResource"];
187 187
 		}
188 188
 		//add query params
189
-		if(isset($api["queryParams"] )){ 
189
+		if (isset($api["queryParams"])) { 
190 190
 			foreach ($api["queryParams"] as $key => $value) {
191 191
 				$required = FALSE;
192
-				if(substr($value,0,1)==="!"){
192
+				if (substr($value, 0, 1) === "!") {
193 193
 					$required = TRUE;
194
-					$value=substr($value,1);
194
+					$value = substr($value, 1);
195 195
 				}
196
-				$index = explode("->",$value);
196
+				$index = explode("->", $value);
197 197
 				$curIndexArg = $args;
198 198
 				$add = TRUE;
199 199
 				$curkey = "";
200 200
 				foreach ($index as $key1 => $value1) {
201
-					if(!isset($curIndexArg[$value1])&&$value1 !== "*"){
201
+					if (!isset($curIndexArg[$value1]) && $value1 !== "*") {
202 202
 						$add = FALSE;
203
-					}else{
203
+					}else {
204 204
 						$curkey = $value1;
205 205
 						//星号表示所有,按照暂时的业务,默认星号后面就没了
206
-						if($curkey == "*"){
206
+						if ($curkey == "*") {
207 207
 							foreach ($curIndexArg as $queryK => $queryV) {
208
-								if(!is_array($queryV)){
209
-									$request->addQueryParams($queryK,$queryV);
208
+								if (!is_array($queryV)) {
209
+									$request->addQueryParams($queryK, $queryV);
210 210
 								}
211 211
 							}
212 212
 							$add = FALSE;
213 213
 							$required = FALSE;
214 214
 							break;
215
-						}else{
215
+						}else {
216 216
 							$curIndexArg = $curIndexArg[$value1];
217 217
 						}
218 218
 					}
219 219
 				}
220
-				if(!empty($curIndexArg)&&$add){
221
-					$request->addQueryParams($curkey,$curIndexArg);
220
+				if (!empty($curIndexArg) && $add) {
221
+					$request->addQueryParams($curkey, $curIndexArg);
222 222
 					continue;
223 223
 				}
224
-				if($required)
224
+				if ($required)
225 225
 					throw new Ks3ClientException($method." param ".$value." is required");
226 226
 			}
227 227
 		}
228
-		if(isset($api["body"])){
229
-			if(isset($api["body"]["builder"])){
228
+		if (isset($api["body"])) {
229
+			if (isset($api["body"]["builder"])) {
230 230
 				$builderName = $api["body"]["builder"];
231 231
 				$builder = new $builderName();
232 232
 				$request->body = $builder->build($args);
233
-			}else if(isset($api["body"]["position"])){
233
+			}else if (isset($api["body"]["position"])) {
234 234
 				$position = $api["body"]["position"];
235
-				$index = explode("->",$position);
235
+				$index = explode("->", $position);
236 236
 				$curIndexArg = $args;
237 237
 				$add = TRUE;
238 238
 				$curkey = "";
239 239
 				foreach ($index as $key1 => $value1) {
240
-					if(!isset($curIndexArg[$value1])){
240
+					if (!isset($curIndexArg[$value1])) {
241 241
 						$add = FALSE;
242
-					}else{
242
+					}else {
243 243
 						$curIndexArg = $curIndexArg[$value1];
244 244
 						$curkey = $value1;
245 245
 					}
246 246
 				}
247
-				if(!empty($curIndexArg)&&$add){
248
-					$request->body=$curIndexArg;
247
+				if (!empty($curIndexArg) && $add) {
248
+					$request->body = $curIndexArg;
249 249
 				}
250 250
 			}
251 251
 		}
@@ -254,107 +254,107 @@  discard block
 block discarded – undo
254 254
 		//TODO
255 255
 		//sign request
256 256
 		$signer = NULL;
257
-		if(isset($api["signer"])){
258
-			$signers = explode("->",$api["signer"]);
257
+		if (isset($api["signer"])) {
258
+			$signers = explode("->", $api["signer"]);
259 259
 			foreach ($signers as $key => $value) {
260 260
 				$signer = new $value();
261
-				$log = $signer->sign($request,array("accessKey"=>$this->accessKey,"secretKey"=>$this->secretKey,"args"=>$args));
262
-				if(!empty($log)){
263
-					$holder->msg.=$log."\r\n";
261
+				$log = $signer->sign($request, array("accessKey"=>$this->accessKey, "secretKey"=>$this->secretKey, "args"=>$args));
262
+				if (!empty($log)) {
263
+					$holder->msg .= $log."\r\n";
264 264
 				}
265 265
 			}
266 266
 		}
267 267
 
268
-		if($signer===NULL||!($signer instanceof QueryAuthSigner)){
268
+		if ($signer === NULL || !($signer instanceof QueryAuthSigner)) {
269 269
 			$url = $request->toUrl($this->endpoint);
270
-			if($location!=NULL)
270
+			if ($location != NULL)
271 271
 				$url = $location;
272 272
 			$httpRequest = new RequestCore($url);
273
-			if(KS3_API_DEBUG_MODE===TRUE)
274
-				$httpRequest->debug_mode=TRUE;
273
+			if (KS3_API_DEBUG_MODE === TRUE)
274
+				$httpRequest->debug_mode = TRUE;
275 275
 			$httpRequest->set_method($request->method);
276 276
 			foreach ($request->headers as $key => $value) {
277
-				$httpRequest->add_header($key,$value);
277
+				$httpRequest->add_header($key, $value);
278 278
 			}
279
-			$httpRequest->request_body=$request->body;
279
+			$httpRequest->request_body = $request->body;
280 280
 
281
-			if(isset($args["writeCallBack"])){
281
+			if (isset($args["writeCallBack"])) {
282 282
 				$httpRequest->register_streaming_write_callback($args["writeCallBack"]);
283 283
 			}
284
-			if(isset($args["readCallBack"])){
284
+			if (isset($args["readCallBack"])) {
285 285
 				$httpRequest->register_streaming_read_callback($args["readCallBack"]);
286 286
 			}
287 287
 
288 288
 			$read_stream = $request->read_stream;
289 289
 			$read_length = $request->getHeader(Headers::$ContentLength);
290 290
 			$seek_position = $request->seek_position;
291
-			if(isset($read_stream))
291
+			if (isset($read_stream))
292 292
 			{
293
-				$httpRequest->set_read_stream($read_stream,$read_length);
293
+				$httpRequest->set_read_stream($read_stream, $read_length);
294 294
 				$httpRequest->set_seek_position($seek_position);
295 295
 				$httpRequest->remove_header(Headers::$ContentLength);
296 296
 			}
297 297
 			$write_stream = $request->write_stream;
298
-			if(isset($write_stream)){
298
+			if (isset($write_stream)) {
299 299
 				$httpRequest->set_write_stream($write_stream);
300 300
 			}
301 301
 
302
-			$holder->msg.="request url->".serialize($httpRequest->request_url)."\r\n";
303
-			$holder->msg.="request headers->".serialize($httpRequest->request_headers)."\r\n";
304
-			$holder->msg.="request body->".$httpRequest->request_body."\r\n";
305
-			$holder->msg.="request read stream length->".$read_length."\r\n";
306
-			$holder->msg.="request read stream seek position->".$seek_position."\r\n";
302
+			$holder->msg .= "request url->".serialize($httpRequest->request_url)."\r\n";
303
+			$holder->msg .= "request headers->".serialize($httpRequest->request_headers)."\r\n";
304
+			$holder->msg .= "request body->".$httpRequest->request_body."\r\n";
305
+			$holder->msg .= "request read stream length->".$read_length."\r\n";
306
+			$holder->msg .= "request read stream seek position->".$seek_position."\r\n";
307 307
 			$httpRequest->send_request();
308 308
 			//print_r($httpRequest);
309
-			$body = $httpRequest->get_response_body ();	
310
-			$data =  new ResponseCore ( $httpRequest->get_response_header() , Utils::replaceNS2($body), $httpRequest->get_response_code () );
309
+			$body = $httpRequest->get_response_body();	
310
+			$data = new ResponseCore($httpRequest->get_response_header(), Utils::replaceNS2($body), $httpRequest->get_response_code());
311 311
 
312
-			if($data->status == 307){
312
+			if ($data->status == 307) {
313 313
 				$respHeaders = $httpRequest->get_response_header();
314 314
 				$location = $respHeaders["location"];
315
-				if(substr($location,0,4) == "http"){
316
-					$holder->msg.="response code->".$httpRequest->get_response_code ()."\r\n";
317
-					$holder->msg.="response headers->".serialize($httpRequest->get_response_header())."\r\n";
318
-					$holder->msg.="response body->".$body."\r\n";
319
-					$holder->msg.="retry request to ".$location."\r\n";
315
+				if (substr($location, 0, 4) == "http") {
316
+					$holder->msg .= "response code->".$httpRequest->get_response_code()."\r\n";
317
+					$holder->msg .= "response headers->".serialize($httpRequest->get_response_header())."\r\n";
318
+					$holder->msg .= "response body->".$body."\r\n";
319
+					$holder->msg .= "retry request to ".$location."\r\n";
320 320
 					//array($args)详见invoke开头
321
-					return $this->invoke($method,array($args),$holder,$location);
321
+					return $this->invoke($method, array($args), $holder, $location);
322 322
 				}
323 323
 			}
324
-			$holder->msg.="response code->".$httpRequest->get_response_code ()."\r\n";
325
-			$holder->msg.="response headers->".serialize($httpRequest->get_response_header())."\r\n";
326
-			$holder->msg.="response body->".$body."\r\n";
327
-			$handlers = explode("->",$api["handler"]);
324
+			$holder->msg .= "response code->".$httpRequest->get_response_code()."\r\n";
325
+			$holder->msg .= "response headers->".serialize($httpRequest->get_response_header())."\r\n";
326
+			$holder->msg .= "response body->".$body."\r\n";
327
+			$handlers = explode("->", $api["handler"]);
328 328
 			foreach ($handlers as $key => $value) {
329 329
 				$handler = new $value();
330 330
 				$data = $handler->handle($data);
331 331
 			}
332 332
 			return $data;
333
-		}else{
333
+		}else {
334 334
 			$url = $request->toUrl($this->endpoint);
335
-			$holder->msg.=$url."\r\n";
335
+			$holder->msg .= $url."\r\n";
336 336
 			return $url;
337 337
 		}
338 338
 	}
339 339
 	//用于生产表单上传时的签名信息
340
-	public function postObject($bucket ,$postFormData=array(),$unknowValueFormFiled=array(),$filename=NULL,$expire=18000){
340
+	public function postObject($bucket, $postFormData = array(), $unknowValueFormFiled = array(), $filename = NULL, $expire = 18000) {
341 341
 		$policy = array();
342 342
 
343 343
 		$expireTime = Utils::iso8601(time()+$expire);
344 344
 		$policy["expiration"] = $expireTime;
345
-		$postFormData["bucket"]=$bucket;
345
+		$postFormData["bucket"] = $bucket;
346 346
 		$conditions = array();
347 347
 		foreach ($postFormData as $key => $value) {
348 348
 			$condition = array();
349
-			$condition[$key] = str_replace("\${filename}",$filename, $value);
350
-			array_push($conditions,$condition);
349
+			$condition[$key] = str_replace("\${filename}", $filename, $value);
350
+			array_push($conditions, $condition);
351 351
 		}
352 352
 		foreach ($unknowValueFormFiled as $key => $value) {
353 353
 			$condition = array();
354
-			array_push($condition,"starts-with");
355
-			array_push($condition,"\$".$value);
356
-			array_push($condition,"");
357
-			array_push($conditions,$condition);
354
+			array_push($condition, "starts-with");
355
+			array_push($condition, "\$".$value);
356
+			array_push($condition, "");
357
+			array_push($conditions, $condition);
358 358
 		}
359 359
 		$policy["conditions"] = $conditions;
360 360
 		$json = json_encode($policy);
Please login to merge, or discard this patch.
Braces   +50 added lines, -38 removed lines patch added patch discarded remove patch
@@ -4,26 +4,33 @@  discard block
 block discarded – undo
4 4
 date_default_timezone_set('Asia/Shanghai');
5 5
 
6 6
 //检测API路径
7
-if(!defined("KS3_API_PATH"))
8
-define("KS3_API_PATH", dirname(__FILE__));
7
+if(!defined("KS3_API_PATH")) {
8
+    define("KS3_API_PATH", dirname(__FILE__));
9
+}
9 10
 //是否使用VHOST
10
-if(!defined("KS3_API_VHOST"))
11
-define("KS3_API_VHOST",TRUE);
11
+if(!defined("KS3_API_VHOST")) {
12
+    define("KS3_API_VHOST",TRUE);
13
+}
12 14
 //是否开启日志(写入日志文件)
13
-if(!defined("KS3_API_LOG"))
14
-define("KS3_API_LOG",TRUE);
15
+if(!defined("KS3_API_LOG")) {
16
+    define("KS3_API_LOG",TRUE);
17
+}
15 18
 //是否显示日志(直接输出日志)
16
-if(!defined("KS3_API_DISPLAY_LOG"))
17
-define("KS3_API_DISPLAY_LOG", TRUE);
19
+if(!defined("KS3_API_DISPLAY_LOG")) {
20
+    define("KS3_API_DISPLAY_LOG", TRUE);
21
+}
18 22
 //定义日志目录(默认是该项目log下)
19
-if(!defined("KS3_API_LOG_PATH"))
20
-define("KS3_API_LOG_PATH","");
23
+if(!defined("KS3_API_LOG_PATH")) {
24
+    define("KS3_API_LOG_PATH","");
25
+}
21 26
 //是否使用HTTPS
22
-if(!defined("KS3_API_USE_HTTPS"))
23
-define("KS3_API_USE_HTTPS",FALSE);
27
+if(!defined("KS3_API_USE_HTTPS")) {
28
+    define("KS3_API_USE_HTTPS",FALSE);
29
+}
24 30
 //是否开启curl debug模式
25
-if(!defined("KS3_API_DEBUG_MODE"))
26
-define("KS3_API_DEBUG_MODE",FALSE);
31
+if(!defined("KS3_API_DEBUG_MODE")) {
32
+    define("KS3_API_DEBUG_MODE",FALSE);
33
+}
27 34
 define("KS3_API_Author","[email protected]");
28 35
 define("KS3_API_Version","1.2");
29 36
 
@@ -49,10 +56,10 @@  discard block
 block discarded – undo
49 56
 			throw new Ks3ClientException("please install mbstring extension");
50 57
 			
51 58
 		}
52
-	}else{
59
+	} else{
53 60
 		throw new Ks3ClientException("please install extensions");
54 61
 	}
55
-}else{
62
+} else{
56 63
 	throw new Ks3ClientException();
57 64
 }
58 65
 
@@ -116,14 +123,15 @@  discard block
 block discarded – undo
116 123
 		$ex = NULL;
117 124
 		try{
118 125
 			$result = $this->invoke($method,$args,$holder);
119
-		}catch(Exception $e){
126
+		} catch(Exception $e){
120 127
 			$holder->msg.=$e."\r\n";
121 128
 			$ex = $e;
122 129
 		}
123 130
 		$holder->msg .= "------------------Logging End-------------------------\r\n";
124 131
 		$this->log->info($holder->msg);
125
-		if($ex !=NULL)
126
-			throw $ex;
132
+		if($ex !=NULL) {
133
+					throw $ex;
134
+		}
127 135
 		return $result;
128 136
 	}
129 137
 	private function invoke($method,$args=array(),$holder,$location=NULL){
@@ -145,7 +153,7 @@  discard block
 block discarded – undo
145 153
 			if($api["needBucket"]){
146 154
 				throw new Ks3ClientException($method." this api need bucket");
147 155
 			}
148
-		}else{
156
+		} else{
149 157
 			$request->bucket = $args["Bucket"];
150 158
 		}
151 159
 		$position = "Key";
@@ -157,7 +165,7 @@  discard block
 block discarded – undo
157 165
 			if($api["needObject"]){
158 166
 				throw new Ks3ClientException($method." this api need ".$position);
159 167
 			}
160
-		}else{
168
+		} else{
161 169
 			$key = $args[$position];
162 170
 			$preEncoding = mb_detect_encoding($key, array("ASCII","UTF-8","GB2312","GBK","BIG5"));
163 171
 			$holder->msg.="key encoding ".$preEncoding."\r\n";
@@ -170,16 +178,17 @@  discard block
 block discarded – undo
170 178
 		if($method == "Method"){
171 179
 			if(empty($args["Method"])){
172 180
 				$request->method="GET";
173
-			}else{
181
+			} else{
174 182
 				$request->method=$args["Method"];
175 183
 			}
176
-		}else{
184
+		} else{
177 185
 			$request->method=$api["method"];
178 186
 		}
179
-		if(KS3_API_USE_HTTPS)
180
-			$request->scheme="https://";
181
-		else
182
-			$request->scheme="http://";
187
+		if(KS3_API_USE_HTTPS) {
188
+					$request->scheme="https://";
189
+		} else {
190
+					$request->scheme="http://";
191
+		}
183 192
 		$request->endpoint=$this->endpoint;
184 193
 		//add subresource
185 194
 		if(!empty($api["subResource"])){
@@ -200,7 +209,7 @@  discard block
 block discarded – undo
200 209
 				foreach ($index as $key1 => $value1) {
201 210
 					if(!isset($curIndexArg[$value1])&&$value1 !== "*"){
202 211
 						$add = FALSE;
203
-					}else{
212
+					} else{
204 213
 						$curkey = $value1;
205 214
 						//星号表示所有,按照暂时的业务,默认星号后面就没了
206 215
 						if($curkey == "*"){
@@ -212,7 +221,7 @@  discard block
 block discarded – undo
212 221
 							$add = FALSE;
213 222
 							$required = FALSE;
214 223
 							break;
215
-						}else{
224
+						} else{
216 225
 							$curIndexArg = $curIndexArg[$value1];
217 226
 						}
218 227
 					}
@@ -221,8 +230,9 @@  discard block
 block discarded – undo
221 230
 					$request->addQueryParams($curkey,$curIndexArg);
222 231
 					continue;
223 232
 				}
224
-				if($required)
225
-					throw new Ks3ClientException($method." param ".$value." is required");
233
+				if($required) {
234
+									throw new Ks3ClientException($method." param ".$value." is required");
235
+				}
226 236
 			}
227 237
 		}
228 238
 		if(isset($api["body"])){
@@ -230,7 +240,7 @@  discard block
 block discarded – undo
230 240
 				$builderName = $api["body"]["builder"];
231 241
 				$builder = new $builderName();
232 242
 				$request->body = $builder->build($args);
233
-			}else if(isset($api["body"]["position"])){
243
+			} else if(isset($api["body"]["position"])){
234 244
 				$position = $api["body"]["position"];
235 245
 				$index = explode("->",$position);
236 246
 				$curIndexArg = $args;
@@ -239,7 +249,7 @@  discard block
 block discarded – undo
239 249
 				foreach ($index as $key1 => $value1) {
240 250
 					if(!isset($curIndexArg[$value1])){
241 251
 						$add = FALSE;
242
-					}else{
252
+					} else{
243 253
 						$curIndexArg = $curIndexArg[$value1];
244 254
 						$curkey = $value1;
245 255
 					}
@@ -267,11 +277,13 @@  discard block
 block discarded – undo
267 277
 
268 278
 		if($signer===NULL||!($signer instanceof QueryAuthSigner)){
269 279
 			$url = $request->toUrl($this->endpoint);
270
-			if($location!=NULL)
271
-				$url = $location;
280
+			if($location!=NULL) {
281
+							$url = $location;
282
+			}
272 283
 			$httpRequest = new RequestCore($url);
273
-			if(KS3_API_DEBUG_MODE===TRUE)
274
-				$httpRequest->debug_mode=TRUE;
284
+			if(KS3_API_DEBUG_MODE===TRUE) {
285
+							$httpRequest->debug_mode=TRUE;
286
+			}
275 287
 			$httpRequest->set_method($request->method);
276 288
 			foreach ($request->headers as $key => $value) {
277 289
 				$httpRequest->add_header($key,$value);
@@ -330,7 +342,7 @@  discard block
 block discarded – undo
330 342
 				$data = $handler->handle($data);
331 343
 			}
332 344
 			return $data;
333
-		}else{
345
+		} else{
334 346
 			$url = $request->toUrl($this->endpoint);
335 347
 			$holder->msg.=$url."\r\n";
336 348
 			return $url;
Please login to merge, or discard this patch.
src/service/ksyun/bin/config/Consts.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -2,53 +2,53 @@
 block discarded – undo
2 2
 require_once KS3_API_PATH.DIRECTORY_SEPARATOR."core".DIRECTORY_SEPARATOR."Headers.php";
3 3
 
4 4
 class Consts {
5
-	// static $Ks3EndPoint = "kss.ksyun.com";
6
-	static $SubResource = array("acl", "lifecycle", "location", "logging", "notification", "policy", "requestPayment", "torrent", "uploadId", "uploads", "versionId","versioning", "versions", "website", "delete", "thumbnail","cors","pfop","querypfop","adp","queryadp");	
7
-	static $QueryParam = array("partNumber","response-content-type","response-content-language","response-expires", "response-cache-control","response-content-disposition", "response-content-encoding", );
8
-	static $Acl = array("private","public-read","public-read-write");
9
-	static $KS3HeaderPrefix = "x-kss-";
10
-	static $CORSElements = array("AllowedMethod","AllowedOrigin","AllowedHeader","MaxAgeSeconds","ExposeHeader");
11
-	static $BucketLoggingElements = array("TargetBucket","TargetPrefix");
12
-	static $ObjectMeta = array("Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires");
13
-	static $MultipartObjectMeta = array("Cache-Control","Content-Disposition","Content-Encoding","Content-Type","Expires");
14
-	static $UserMetaPrefix = "x-kss-meta";
15
-	static $ResponseObjectMeta = array(
16
-		"cache-control"=>"Cache-Control",
17
-		"content-disposition"=>"Content-Disposition",
18
-		"content-encoding"=>"Content-Encoding",
19
-		"etag"=>"ETag",
20
-		"content-type"=>"Content-Type",
21
-		"expires"=>"Expires",
22
-		"last-modified"=>"Last-Modified",
23
-		"content-range"=>"Content-Range",
24
-		"content-length"=>"Content-Length",
25
-		"x-kss-server-side-encryption"=>"SSEAlgm",
26
-		"x-kss-server-side-encryption-kss-kms-key-id"=>"SSEKMSId",
27
-		"x-kss-server-side-encryption-customer-algorithm"=>"SSECAlgm",
28
-		"x-kss-server-side-encryption-customer-key-md5"=>"SSECKeyMD5"
29
-		);
30
-	static $PartsElement = array("PartNumber","ETag");
31
-	static $UploadHandler = array(
32
-		"etag"=>"ETag",
33
-		"taskid"=>"TaskID",
34
-		"x-kss-server-side-encryption"=>"SSEAlgm",
35
-		"x-kss-server-side-encryption-kss-kms-key-id"=>"SSEKMSId",
36
-		"x-kss-server-side-encryption-customer-algorithm"=>"SSECAlgm",
37
-		"x-kss-server-side-encryption-customer-key-md5"=>"SSECKeyMD5"
38
-		);
39
-	static $SSEHandler = array(
40
-		"x-kss-server-side-encryption"=>"SSEAlgm",
41
-		"x-kss-server-side-encryption-kss-kms-key-id"=>"SSEKMSId",
42
-		"x-kss-server-side-encryption-customer-algorithm"=>"SSECAlgm",
43
-		"x-kss-server-side-encryption-customer-key-md5"=>"SSECKeyMD5"
44
-		);
45
-	static $Permission_Read = "READ";
46
-	static $Permission_Write = "WRITE";
47
-	static $Grantee_Group_All = "http://acs.ksyun.com/groups/global/AllUsers";
48
-	static $ResponseOverrides = array("response-expires","response-content-encoding","response-content-disposition",
49
-		"response-content-language","response-content-type","response-cache-control");
50
-	static $CallBackMagics = array("bucket","key","etag","objectSize","mimeType","createTime");
51
-	static $UserAgent = "ks3-kss-php-sdk";
52
-	static $SSEDefaultAlgm = "AES256";
5
+    // static $Ks3EndPoint = "kss.ksyun.com";
6
+    static $SubResource = array("acl", "lifecycle", "location", "logging", "notification", "policy", "requestPayment", "torrent", "uploadId", "uploads", "versionId","versioning", "versions", "website", "delete", "thumbnail","cors","pfop","querypfop","adp","queryadp");	
7
+    static $QueryParam = array("partNumber","response-content-type","response-content-language","response-expires", "response-cache-control","response-content-disposition", "response-content-encoding", );
8
+    static $Acl = array("private","public-read","public-read-write");
9
+    static $KS3HeaderPrefix = "x-kss-";
10
+    static $CORSElements = array("AllowedMethod","AllowedOrigin","AllowedHeader","MaxAgeSeconds","ExposeHeader");
11
+    static $BucketLoggingElements = array("TargetBucket","TargetPrefix");
12
+    static $ObjectMeta = array("Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires");
13
+    static $MultipartObjectMeta = array("Cache-Control","Content-Disposition","Content-Encoding","Content-Type","Expires");
14
+    static $UserMetaPrefix = "x-kss-meta";
15
+    static $ResponseObjectMeta = array(
16
+        "cache-control"=>"Cache-Control",
17
+        "content-disposition"=>"Content-Disposition",
18
+        "content-encoding"=>"Content-Encoding",
19
+        "etag"=>"ETag",
20
+        "content-type"=>"Content-Type",
21
+        "expires"=>"Expires",
22
+        "last-modified"=>"Last-Modified",
23
+        "content-range"=>"Content-Range",
24
+        "content-length"=>"Content-Length",
25
+        "x-kss-server-side-encryption"=>"SSEAlgm",
26
+        "x-kss-server-side-encryption-kss-kms-key-id"=>"SSEKMSId",
27
+        "x-kss-server-side-encryption-customer-algorithm"=>"SSECAlgm",
28
+        "x-kss-server-side-encryption-customer-key-md5"=>"SSECKeyMD5"
29
+        );
30
+    static $PartsElement = array("PartNumber","ETag");
31
+    static $UploadHandler = array(
32
+        "etag"=>"ETag",
33
+        "taskid"=>"TaskID",
34
+        "x-kss-server-side-encryption"=>"SSEAlgm",
35
+        "x-kss-server-side-encryption-kss-kms-key-id"=>"SSEKMSId",
36
+        "x-kss-server-side-encryption-customer-algorithm"=>"SSECAlgm",
37
+        "x-kss-server-side-encryption-customer-key-md5"=>"SSECKeyMD5"
38
+        );
39
+    static $SSEHandler = array(
40
+        "x-kss-server-side-encryption"=>"SSEAlgm",
41
+        "x-kss-server-side-encryption-kss-kms-key-id"=>"SSEKMSId",
42
+        "x-kss-server-side-encryption-customer-algorithm"=>"SSECAlgm",
43
+        "x-kss-server-side-encryption-customer-key-md5"=>"SSECKeyMD5"
44
+        );
45
+    static $Permission_Read = "READ";
46
+    static $Permission_Write = "WRITE";
47
+    static $Grantee_Group_All = "http://acs.ksyun.com/groups/global/AllUsers";
48
+    static $ResponseOverrides = array("response-expires","response-content-encoding","response-content-disposition",
49
+        "response-content-language","response-content-type","response-cache-control");
50
+    static $CallBackMagics = array("bucket","key","etag","objectSize","mimeType","createTime");
51
+    static $UserAgent = "ks3-kss-php-sdk";
52
+    static $SSEDefaultAlgm = "AES256";
53 53
 }
54 54
 ?>
55 55
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -3,14 +3,14 @@  discard block
 block discarded – undo
3 3
 
4 4
 class Consts {
5 5
 	// static $Ks3EndPoint = "kss.ksyun.com";
6
-	static $SubResource = array("acl", "lifecycle", "location", "logging", "notification", "policy", "requestPayment", "torrent", "uploadId", "uploads", "versionId","versioning", "versions", "website", "delete", "thumbnail","cors","pfop","querypfop","adp","queryadp");	
7
-	static $QueryParam = array("partNumber","response-content-type","response-content-language","response-expires", "response-cache-control","response-content-disposition", "response-content-encoding", );
8
-	static $Acl = array("private","public-read","public-read-write");
6
+	static $SubResource = array("acl", "lifecycle", "location", "logging", "notification", "policy", "requestPayment", "torrent", "uploadId", "uploads", "versionId", "versioning", "versions", "website", "delete", "thumbnail", "cors", "pfop", "querypfop", "adp", "queryadp");	
7
+	static $QueryParam = array("partNumber", "response-content-type", "response-content-language", "response-expires", "response-cache-control", "response-content-disposition", "response-content-encoding",);
8
+	static $Acl = array("private", "public-read", "public-read-write");
9 9
 	static $KS3HeaderPrefix = "x-kss-";
10
-	static $CORSElements = array("AllowedMethod","AllowedOrigin","AllowedHeader","MaxAgeSeconds","ExposeHeader");
11
-	static $BucketLoggingElements = array("TargetBucket","TargetPrefix");
12
-	static $ObjectMeta = array("Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires");
13
-	static $MultipartObjectMeta = array("Cache-Control","Content-Disposition","Content-Encoding","Content-Type","Expires");
10
+	static $CORSElements = array("AllowedMethod", "AllowedOrigin", "AllowedHeader", "MaxAgeSeconds", "ExposeHeader");
11
+	static $BucketLoggingElements = array("TargetBucket", "TargetPrefix");
12
+	static $ObjectMeta = array("Cache-Control", "Content-Disposition", "Content-Encoding", "Content-Length", "Content-MD5", "Content-Type", "Expires");
13
+	static $MultipartObjectMeta = array("Cache-Control", "Content-Disposition", "Content-Encoding", "Content-Type", "Expires");
14 14
 	static $UserMetaPrefix = "x-kss-meta";
15 15
 	static $ResponseObjectMeta = array(
16 16
 		"cache-control"=>"Cache-Control",
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 		"x-kss-server-side-encryption-customer-algorithm"=>"SSECAlgm",
28 28
 		"x-kss-server-side-encryption-customer-key-md5"=>"SSECKeyMD5"
29 29
 		);
30
-	static $PartsElement = array("PartNumber","ETag");
30
+	static $PartsElement = array("PartNumber", "ETag");
31 31
 	static $UploadHandler = array(
32 32
 		"etag"=>"ETag",
33 33
 		"taskid"=>"TaskID",
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
 	static $Permission_Read = "READ";
46 46
 	static $Permission_Write = "WRITE";
47 47
 	static $Grantee_Group_All = "http://acs.ksyun.com/groups/global/AllUsers";
48
-	static $ResponseOverrides = array("response-expires","response-content-encoding","response-content-disposition",
49
-		"response-content-language","response-content-type","response-cache-control");
50
-	static $CallBackMagics = array("bucket","key","etag","objectSize","mimeType","createTime");
48
+	static $ResponseOverrides = array("response-expires", "response-content-encoding", "response-content-disposition",
49
+		"response-content-language", "response-content-type", "response-cache-control");
50
+	static $CallBackMagics = array("bucket", "key", "etag", "objectSize", "mimeType", "createTime");
51 51
 	static $UserAgent = "ks3-kss-php-sdk";
52 52
 	static $SSEDefaultAlgm = "AES256";
53 53
 }
Please login to merge, or discard this patch.
src/service/ksyun/bin/unit/Test.php 3 patches
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -7,138 +7,138 @@  discard block
 block discarded – undo
7 7
 require_once "PUnit.php";
8 8
 require_once "../lib/RequestCore.class.php";
9 9
 class SDKTest extends PUnit{
10
-	protected $bucket = "php-sdk-test";
11
-	protected $key = "test==中/文?";
12
-	protected $key_copy = "test中/文_copy?";
13
-	protected $accesskey = "";
14
-	protected $secrectkey = "";
15
-	protected $client;
10
+    protected $bucket = "php-sdk-test";
11
+    protected $key = "test==中/文?";
12
+    protected $key_copy = "test中/文_copy?";
13
+    protected $accesskey = "";
14
+    protected $secrectkey = "";
15
+    protected $client;
16 16
     protected $encryptionClient;
17
-	protected $cachedir;
17
+    protected $cachedir;
18 18
     protected $sseckey;
19
-	public function __construct(){
20
-		$this->client=new Ks3Client($this->accesskey,$this->secrectkey);
21
-		$this->cachedir=KS3_API_PATH.DIRECTORY_SEPARATOR."unit".DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR;
19
+    public function __construct(){
20
+        $this->client=new Ks3Client($this->accesskey,$this->secrectkey);
21
+        $this->cachedir=KS3_API_PATH.DIRECTORY_SEPARATOR."unit".DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR;
22 22
         $filename = "secret.key";
23 23
         $handle = fopen($filename, "r");
24 24
         $sseckey = fread($handle, filesize ($filename));
25 25
         fclose($handle);
26 26
         $this->sseckey = $sseckey;
27 27
         $this->encryptionClient = new Ks3EncryptionClient($this->accesskey,$this->secrectkey,$sseckey);
28
-	}
29
-	public function before(){
30
-		if($this->client->bucketExists(array("Bucket"=>$this->bucket))){
31
-			$keys = array();
32
-			$objects = $this->client->listObjects(array("Bucket"=>$this->bucket));
33
-			foreach ($objects["Contents"] as $object) {
34
-				array_push($keys, $object["Key"]);
35
-			}
36
-			$this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>$keys));
37
-		}else{
38
-			$this->client->createBucket(array("Bucket"=>$this->bucket));
39
-		}
40
-	}
41
-	public function testListBuckets(){
42
-		$buckets = $this->client->listBuckets();
43
-		$found = FALSE;
44
-		foreach ($buckets as $bucket) {
45
-			if($bucket["Name"] == $this->bucket)
46
-				$found = TRUE;
47
-		}
48
-		if(!$found)
49
-			throw new Exception("list buckets expected found ".$this->bucket.",but not found");
28
+    }
29
+    public function before(){
30
+        if($this->client->bucketExists(array("Bucket"=>$this->bucket))){
31
+            $keys = array();
32
+            $objects = $this->client->listObjects(array("Bucket"=>$this->bucket));
33
+            foreach ($objects["Contents"] as $object) {
34
+                array_push($keys, $object["Key"]);
35
+            }
36
+            $this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>$keys));
37
+        }else{
38
+            $this->client->createBucket(array("Bucket"=>$this->bucket));
39
+        }
40
+    }
41
+    public function testListBuckets(){
42
+        $buckets = $this->client->listBuckets();
43
+        $found = FALSE;
44
+        foreach ($buckets as $bucket) {
45
+            if($bucket["Name"] == $this->bucket)
46
+                $found = TRUE;
47
+        }
48
+        if(!$found)
49
+            throw new Exception("list buckets expected found ".$this->bucket.",but not found");
50 50
 			
51
-	}
52
-	public function testDeleteBucket(){
53
-		$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>"test","Content"=>""));
54
-		$ex = NULL;
55
-		try{
56
-			$this->client->deleteBucket(array("Bucket"=>$this->bucket));
57
-		}catch(Exception $e){
58
-			$ex = $e;
59
-		}
60
-		if($ex == NULL||!($ex->errorCode === "BucketNotEmpty")){
61
-			throw new Exception("delete bucket expected BucketNotEmpty but ".$ex);
62
-		}
63
-	}
64
-	public function testBucketCORS(){
65
-		$this->client->setBucketCORS($args = array(
66
-       		"Bucket"=>$this->bucket,
67
-        	"CORS"=>array(
68
-        		array(
69
-           			"AllowedMethod"=>array("GET","PUT"),
70
-            		"AllowedOrigin"=>array("http://www.kingsoft.com"),
71
-            		"AllowedHeader"=>array("*"),
72
-            		"ExposeHeader"=>array("*"),
73
-            		"MaxAgeSeconds"=>10
74
-        		),
75
-        		array(
76
-         		  "AllowedMethod"=>array("GET","PUT"),
77
-          		  "AllowedOrigin"=>array("*"),
78
-          		  "AllowedHeader"=>array("*"),
79
-          		  "ExposeHeader"=>array("*"),
80
-          		  "MaxAgeSeconds"=>10
81
-        		)
82
-    		)));
83
- 	    $cors = $this->client->getBucketCORS(array("Bucket"=>$this->bucket));
84
- 	    $this->assertEquals(count($cors),2,"bucket cors count ");
85
-   		$this->client->deleteBucketCORS(array("Bucket"=>$this->bucket));
86
-   		$cors = $this->client->getBucketCORS(array("Bucket"=>$this->bucket));
87
-		$this->assertEquals(count($cors),0,"bucket cors count ");
88
-	}
89
-	public function testCreateBucket(){
90
-		$ex = NULL;
91
-		try{
92
-			$this->client->createBucket(array("Bucket"=>$this->bucket));
93
-		}catch(Exception $e){
94
-			$ex = $e;
95
-		}
96
-		if($ex == NULL||!($ex->errorCode === "BucketAlreadyExists")){
97
-			throw new Exception("create bucket expected BucketAlreadyExists but ".$ex);
98
-		}
99
-	}
100
-	public function testACL(){
101
-		$this->client->setBucketAcl(array("Bucket"=>$this->bucket,"ACL"=>"public-read"));
102
-		$acl = $this->client->getBucketAcl(array("Bucket"=>$this->bucket));
103
-		$this->assertEquals($acl,"public-read","bucket acl");
104
-	}
105
-	public function testBucketLogging(){
106
-		$this->client->setBucketLogging(array(
107
-        	"Bucket"=>$this->bucket,
108
-        	"BucketLogging"=>array(
109
-            	"Enable"=>TRUE,
110
-            	"TargetBucket"=>$this->bucket,
111
-            	"TargetPrefix"=>"X-KSS"
51
+    }
52
+    public function testDeleteBucket(){
53
+        $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>"test","Content"=>""));
54
+        $ex = NULL;
55
+        try{
56
+            $this->client->deleteBucket(array("Bucket"=>$this->bucket));
57
+        }catch(Exception $e){
58
+            $ex = $e;
59
+        }
60
+        if($ex == NULL||!($ex->errorCode === "BucketNotEmpty")){
61
+            throw new Exception("delete bucket expected BucketNotEmpty but ".$ex);
62
+        }
63
+    }
64
+    public function testBucketCORS(){
65
+        $this->client->setBucketCORS($args = array(
66
+                "Bucket"=>$this->bucket,
67
+            "CORS"=>array(
68
+                array(
69
+                        "AllowedMethod"=>array("GET","PUT"),
70
+                    "AllowedOrigin"=>array("http://www.kingsoft.com"),
71
+                    "AllowedHeader"=>array("*"),
72
+                    "ExposeHeader"=>array("*"),
73
+                    "MaxAgeSeconds"=>10
74
+                ),
75
+                array(
76
+                    "AllowedMethod"=>array("GET","PUT"),
77
+                    "AllowedOrigin"=>array("*"),
78
+                    "AllowedHeader"=>array("*"),
79
+                    "ExposeHeader"=>array("*"),
80
+                    "MaxAgeSeconds"=>10
81
+                )
82
+            )));
83
+            $cors = $this->client->getBucketCORS(array("Bucket"=>$this->bucket));
84
+            $this->assertEquals(count($cors),2,"bucket cors count ");
85
+            $this->client->deleteBucketCORS(array("Bucket"=>$this->bucket));
86
+            $cors = $this->client->getBucketCORS(array("Bucket"=>$this->bucket));
87
+        $this->assertEquals(count($cors),0,"bucket cors count ");
88
+    }
89
+    public function testCreateBucket(){
90
+        $ex = NULL;
91
+        try{
92
+            $this->client->createBucket(array("Bucket"=>$this->bucket));
93
+        }catch(Exception $e){
94
+            $ex = $e;
95
+        }
96
+        if($ex == NULL||!($ex->errorCode === "BucketAlreadyExists")){
97
+            throw new Exception("create bucket expected BucketAlreadyExists but ".$ex);
98
+        }
99
+    }
100
+    public function testACL(){
101
+        $this->client->setBucketAcl(array("Bucket"=>$this->bucket,"ACL"=>"public-read"));
102
+        $acl = $this->client->getBucketAcl(array("Bucket"=>$this->bucket));
103
+        $this->assertEquals($acl,"public-read","bucket acl");
104
+    }
105
+    public function testBucketLogging(){
106
+        $this->client->setBucketLogging(array(
107
+            "Bucket"=>$this->bucket,
108
+            "BucketLogging"=>array(
109
+                "Enable"=>TRUE,
110
+                "TargetBucket"=>$this->bucket,
111
+                "TargetPrefix"=>"X-KSS"
112 112
             )
113 113
         ));
114
-    	$logging = $this->client->getBucketLogging(array("Bucket"=>$this->bucket));
115
-    	$this->assertEquals($logging["Enable"],TRUE,"bucket logging enable");
114
+        $logging = $this->client->getBucketLogging(array("Bucket"=>$this->bucket));
115
+        $this->assertEquals($logging["Enable"],TRUE,"bucket logging enable");
116 116
 
117
-    	$this->client->setBucketLogging(array(
118
-    		"Bucket"=>$this->bucket,
119
-    		"BucketLogging"=>array(
120
-        		"Enable"=>FALSE,//是否开启
121
-        	)
122
-    	));
123
-    	$logging = $this->client->getBucketLogging(array("Bucket"=>$this->bucket));
124
-    	$this->assertEquals($logging["Enable"],FALSE,"bucket logging enable");
125
-	}
126
-	public function testBucketLocation(){
127
-		$location = $this->client->getBucketLocation(array("Bucket"=>$this->bucket));
128
-		$this->assertEquals($location,"HANGZHOU","bucket location ");
129
-	}
130
-	public function testPutObjectByContentAndGetObjectContent(){
131
-		$args = array(
132
-        	"Bucket"=>$this->bucket,
133
-        	"Key"=>$this->key,
134
-        	"Content"=>"1234",//要上传的内容
135
-        	"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
136
-        	"ObjectMeta"=>array(
137
-            	"Content-Type"=>"application/xml",
138
-            	"Content-Length"=>3
117
+        $this->client->setBucketLogging(array(
118
+            "Bucket"=>$this->bucket,
119
+            "BucketLogging"=>array(
120
+                "Enable"=>FALSE,//是否开启
121
+            )
122
+        ));
123
+        $logging = $this->client->getBucketLogging(array("Bucket"=>$this->bucket));
124
+        $this->assertEquals($logging["Enable"],FALSE,"bucket logging enable");
125
+    }
126
+    public function testBucketLocation(){
127
+        $location = $this->client->getBucketLocation(array("Bucket"=>$this->bucket));
128
+        $this->assertEquals($location,"HANGZHOU","bucket location ");
129
+    }
130
+    public function testPutObjectByContentAndGetObjectContent(){
131
+        $args = array(
132
+            "Bucket"=>$this->bucket,
133
+            "Key"=>$this->key,
134
+            "Content"=>"1234",//要上传的内容
135
+            "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
136
+            "ObjectMeta"=>array(
137
+                "Content-Type"=>"application/xml",
138
+                "Content-Length"=>3
139 139
             ),
140
-        	"UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头
141
-            	"x-kss-meta-test"=>"test"
140
+            "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头
141
+                "x-kss-meta-test"=>"test"
142 142
             )
143 143
         );
144 144
         $this->client->putObjectByContent($args);
@@ -156,21 +156,21 @@  discard block
 block discarded – undo
156 156
         $this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type");
157 157
         $this->assertEquals($meta["ObjectMeta"]["Content-Length"],3,"Content-Length");
158 158
 
159
-	}
160
-	public function testPutObjectByFile(){
161
-		$args = array(
162
-        	"Bucket"=>$this->bucket,
163
-        	"Key"=>$this->key,
164
-        	"Content"=>array(
165
-        		"content"=>$this->cachedir."test_file"
166
-        	),//要上传的内容
167
-        	"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
168
-        	"ObjectMeta"=>array(
169
-            	"Content-Type"=>"application/xml",
170
-            	"Content-Length"=>100
159
+    }
160
+    public function testPutObjectByFile(){
161
+        $args = array(
162
+            "Bucket"=>$this->bucket,
163
+            "Key"=>$this->key,
164
+            "Content"=>array(
165
+                "content"=>$this->cachedir."test_file"
166
+            ),//要上传的内容
167
+            "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
168
+            "ObjectMeta"=>array(
169
+                "Content-Type"=>"application/xml",
170
+                "Content-Length"=>100
171 171
             ),
172
-        	"UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头
173
-            	"x-kss-meta-test"=>"test"
172
+            "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头
173
+                "x-kss-meta-test"=>"test"
174 174
             )
175 175
         );
176 176
         $this->client->putObjectByFile($args);
@@ -180,47 +180,47 @@  discard block
 block discarded – undo
180 180
         $this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type");
181 181
         $this->assertEquals($meta["ObjectMeta"]["Content-Length"],100,"Content-Length");
182 182
         $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl ");
183
-	}
184
-	public function testObjectAcl(){
185
-		$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key,
183
+    }
184
+    public function testObjectAcl(){
185
+        $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key,
186 186
 "Content"=>"1234","ACL"=>"private"));
187
-		$this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"private","object acl");
188
-		$this->client->setObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key,"ACL"=>"public-read"));
189
-		$this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl");
190
-	}
191
-	public function testDeleteObject(){
192
-		$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key,
187
+        $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"private","object acl");
188
+        $this->client->setObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key,"ACL"=>"public-read"));
189
+        $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl");
190
+    }
191
+    public function testDeleteObject(){
192
+        $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key,
193 193
 "Content"=>"1234"));
194
-		$this->client->deleteObject(array("Bucket"=>$this->bucket,"Key"=>$this->key));
195
-		$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),FALSE,"object exits");
196
-	}
197
-	public function testDeleteObjects(){
198
-		$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key,
194
+        $this->client->deleteObject(array("Bucket"=>$this->bucket,"Key"=>$this->key));
195
+        $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),FALSE,"object exits");
196
+    }
197
+    public function testDeleteObjects(){
198
+        $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key,
199 199
 "Content"=>"1234"));
200
-		$this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>array($this->key)));
201
-		$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),FALSE,"object exits");		
202
-	}
203
-	public function testCopyObject(){
204
-		$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key,
200
+        $this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>array($this->key)));
201
+        $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),FALSE,"object exits");		
202
+    }
203
+    public function testCopyObject(){
204
+        $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key,
205 205
 "Content"=>"1234"));
206
-		$this->client->copyObject(array("Bucket"=>$this->bucket,"Key"=>$this->key_copy,"CopySource"=>array("Bucket"=>$this->bucket,"Key"=>$this->key)));
207
-		$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),TRUE,"object exits");
208
-		$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key_copy)),TRUE
209
-			,"object exits");
210
-	}
211
-	public function testPutAndGetObject(){
212
-		$args = array(
213
-        	"Bucket"=>$this->bucket,
214
-        	"Key"=>$this->key,
215
-        	"Content"=>array(
216
-        		"content"=>$this->cachedir."test_file"
217
-        	),//要上传的内容
218
-        	"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
219
-        	"ObjectMeta"=>array(
220
-            	"Content-Type"=>"application/xml",
206
+        $this->client->copyObject(array("Bucket"=>$this->bucket,"Key"=>$this->key_copy,"CopySource"=>array("Bucket"=>$this->bucket,"Key"=>$this->key)));
207
+        $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),TRUE,"object exits");
208
+        $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key_copy)),TRUE
209
+            ,"object exits");
210
+    }
211
+    public function testPutAndGetObject(){
212
+        $args = array(
213
+            "Bucket"=>$this->bucket,
214
+            "Key"=>$this->key,
215
+            "Content"=>array(
216
+                "content"=>$this->cachedir."test_file"
217
+            ),//要上传的内容
218
+            "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
219
+            "ObjectMeta"=>array(
220
+                "Content-Type"=>"application/xml",
221 221
             ),
222
-        	"UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头
223
-            	"x-kss-meta-test"=>"test"
222
+            "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头
223
+                "x-kss-meta-test"=>"test"
224 224
             )
225 225
         );
226 226
         $this->client->putObjectByFile($args);
@@ -229,49 +229,49 @@  discard block
 block discarded – undo
229 229
         $md5pre = md5_file($this->cachedir."test_file");
230 230
         @unlink($this->cachedir."down");
231 231
         $this->assertEquals($md5,$md5pre,"contentmd5");
232
-	}
233
-	public function testPutAndGetObjectRanges(){
234
-		$args = array(
235
-        	"Bucket"=>$this->bucket,
236
-        	"Key"=>$this->key,
237
-        	"Content"=>array(
238
-        		"content"=>$this->cachedir."test_file"
239
-        	),//要上传的内容
240
-        	"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
241
-        	"ObjectMeta"=>array(
242
-            	"Content-Type"=>"application/xml",
232
+    }
233
+    public function testPutAndGetObjectRanges(){
234
+        $args = array(
235
+            "Bucket"=>$this->bucket,
236
+            "Key"=>$this->key,
237
+            "Content"=>array(
238
+                "content"=>$this->cachedir."test_file"
239
+            ),//要上传的内容
240
+            "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
241
+            "ObjectMeta"=>array(
242
+                "Content-Type"=>"application/xml",
243 243
             ),
244
-        	"UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头
245
-            	"x-kss-meta-test"=>"test"
244
+            "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头
245
+                "x-kss-meta-test"=>"test"
246 246
             )
247 247
         );
248 248
         $this->client->putObjectByFile($args);
249 249
         rangeGetAndCheckMd5($this->client,$this->bucket,$this->key,$this->cachedir."down",md5_file($this->cachedir."test_file"));
250
-	}
251
-	public function testInitAndAbortMultipart(){
252
-		$initResult = $this->client->initMultipartUpload(array("Bucket"=>$this->bucket,"Key"=>$this->key));
253
-		$uid = $initResult["UploadId"];
254
-		$listParts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid)));
255
-		$this->client->abortMultipartUpload(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid)));
256
-		$ex = NULL;
257
-		try{
258
-			$this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid)));
259
-		}catch(Exception $e){
260
-			$ex = $e;
261
-		}
262
-		if($ex == NULL||!($ex->errorCode === "NoSuchUpload")){
263
-			throw new Exception("create bucket expected NoSuchUpload but ".$ex);
264
-		}
265
-	}
266
-	public function testMultipartUpload(){
267
-		generateFile(1024*1024,$this->cachedir."multi");
268
-		//初始化分开上传,获取uploadid
250
+    }
251
+    public function testInitAndAbortMultipart(){
252
+        $initResult = $this->client->initMultipartUpload(array("Bucket"=>$this->bucket,"Key"=>$this->key));
253
+        $uid = $initResult["UploadId"];
254
+        $listParts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid)));
255
+        $this->client->abortMultipartUpload(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid)));
256
+        $ex = NULL;
257
+        try{
258
+            $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid)));
259
+        }catch(Exception $e){
260
+            $ex = $e;
261
+        }
262
+        if($ex == NULL||!($ex->errorCode === "NoSuchUpload")){
263
+            throw new Exception("create bucket expected NoSuchUpload but ".$ex);
264
+        }
265
+    }
266
+    public function testMultipartUpload(){
267
+        generateFile(1024*1024,$this->cachedir."multi");
268
+        //初始化分开上传,获取uploadid
269 269
         $args = array(
270 270
             "Bucket"=>$this->bucket,
271 271
             "Key"=>$this->key,
272 272
             "ACL"=>"public-read",
273 273
             "UserMeta"=>array(
274
-            	"x-kss-meta-test"=>"example"
274
+                "x-kss-meta-test"=>"example"
275 275
             ),
276 276
         "ObjectMeta"=>array(
277 277
             "Content-Type"=>"application/xml"
@@ -323,21 +323,21 @@  discard block
 block discarded – undo
323 323
         $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"],"example","x-kss-meta-test");
324 324
         rangeGetAndCheckMd5($this->client,$this->bucket,$this->key,$this->cachedir."down",md5_file($this->cachedir."multi"));
325 325
         @unlink($this->cachedir."multi");
326
-	}
327
-	public function testListBucketsPresignedUrl(){
328
-		$url = $this->client->generatePresignedUrl(
329
-			array(
330
-				"Method"=>"GET",
331
-				"Options"=>array("Expires"=>60*10),
332
-				"Headers"=>array("Content-Type"=>"text/plain")
333
-				));
334
-		$httpRequest = new RequestCore($url);
335
-		$httpRequest->set_method("GET");
326
+    }
327
+    public function testListBucketsPresignedUrl(){
328
+        $url = $this->client->generatePresignedUrl(
329
+            array(
330
+                "Method"=>"GET",
331
+                "Options"=>array("Expires"=>60*10),
332
+                "Headers"=>array("Content-Type"=>"text/plain")
333
+                ));
334
+        $httpRequest = new RequestCore($url);
335
+        $httpRequest->set_method("GET");
336 336
         $httpRequest->add_header("Content-Type","text/plain");
337
-		$httpRequest->send_request();
338
-		$body = $httpRequest->get_response_body ();	
339
-		$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"list buckets status code");
340
-	}
337
+        $httpRequest->send_request();
338
+        $body = $httpRequest->get_response_body ();	
339
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"list buckets status code");
340
+    }
341 341
     public function testHeadBucketPresignedUrl(){
342 342
         $url = $this->client->generatePresignedUrl(
343 343
             array(
@@ -618,16 +618,16 @@  discard block
 block discarded – undo
618 618
             "Bucket"=>$this->bucket,
619 619
             "Key"=>$this->key,
620 620
             "Content"=>"12345",//要上传的内容
621
-             "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
622
-             "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。
621
+                "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
622
+                "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。
623 623
                 "Content-Type"=>"binay/ocet-stream"
624 624
             ),
625 625
             "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头
626
-              "x-kss-meta-test"=>"test"
626
+                "x-kss-meta-test"=>"test"
627 627
             ),
628 628
             "SSE"=>array(
629 629
                 "Algm"=>"AES256"//暂时支持AES256
630
-             )
630
+                )
631 631
         );
632 632
         $result = $this->client->putObjectByContent($args);
633 633
         $this->assertEquals($result["SSEAlgm"],"AES256");
@@ -645,16 +645,16 @@  discard block
 block discarded – undo
645 645
             "Bucket"=>$this->bucket,
646 646
             "Key"=>$this->key,
647 647
             "Content"=>"12345",//要上传的内容
648
-             "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
649
-             "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。
648
+                "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
649
+                "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。
650 650
                 "Content-Type"=>"binay/ocet-stream"
651 651
             ),
652 652
             "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头
653
-              "x-kss-meta-test"=>"test"
653
+                "x-kss-meta-test"=>"test"
654 654
             ),
655 655
             "SSEC"=>array(
656 656
                 "Key"=>$this->sseckey
657
-             )
657
+                )
658 658
         );
659 659
         $result = $this->client->putObjectByContent($args);
660 660
         $this->assertEquals($result["SSECAlgm"],"AES256");
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
             "Key"=>$this->key,
666 666
             "SSEC"=>array(
667 667
                 "Key"=>$this->sseckey
668
-             )
668
+                )
669 669
             );
670 670
         $result = $this->client->getObjectMeta($args);
671 671
         $this->assertEquals($result["ObjectMeta"]["SSECAlgm"],"AES256");
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
             "WriteTo"=>$this->cachedir."down", //文件保存路径,必须提供。可以是resource
678 678
             "SSEC"=>array(
679 679
                 "Key"=>$this->sseckey
680
-             )
680
+                )
681 681
         );
682 682
         $this->client->getObject($args);
683 683
         $this->assertEquals("12345",file_get_contents($this->cachedir."down"));
@@ -779,16 +779,16 @@  discard block
 block discarded – undo
779 779
             "Bucket"=>$this->bucket,
780 780
             "Key"=>$this->key,
781 781
             "Content"=>"12345",//要上传的内容
782
-             "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
783
-             "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。
782
+                "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
783
+                "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。
784 784
                 "Content-Type"=>"binay/ocet-stream"
785 785
             ),
786 786
             "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头
787
-              "x-kss-meta-test"=>"test"
787
+                "x-kss-meta-test"=>"test"
788 788
             ),
789 789
             "SSEC"=>array(
790 790
                 "Key"=>$this->sseckey
791
-             )
791
+                )
792 792
         );
793 793
         $result = $this->client->putObjectByContent($args);
794 794
 
@@ -799,10 +799,10 @@  discard block
 block discarded – undo
799 799
                 "Bucket"=>$this->bucket,
800 800
                 "Key"=>$this->key
801 801
                 ),
802
-             "SSECSource"=>array(
802
+                "SSECSource"=>array(
803 803
                 "Key"=>$this->sseckey
804 804
                 ),
805
-             "SSEC"=>array(
805
+                "SSEC"=>array(
806 806
                 "Key"=>$this->sseckey
807 807
                 )
808 808
             );
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
             );
822 822
             $this->encryptionClient->putObjectByContent($args);
823 823
             rangeGetAndCheckMd5($this->encryptionClient,$this->bucket,$this->key,
824
-               $this->cachedir."down",md5($args["Content"]));
824
+                $this->cachedir."down",md5($args["Content"]));
825 825
         }
826 826
     }
827 827
     public function testPutObjectByFileAndGetObjectUsingEncyptionMeta(){
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
         );
836 836
         $this->encryptionClient->putObjectByFile($args);
837 837
         rangeGetAndCheckMd5($this->encryptionClient,$this->bucket,$this->key,
838
-               $this->cachedir."down",md5_file($this->cachedir."test_file"));
838
+                $this->cachedir."down",md5_file($this->cachedir."test_file"));
839 839
     }
840 840
     public function testMultipartUploadUsingEncyptionMeta(){
841 841
         generateFile(1024*1024,$this->cachedir."multi");
Please login to merge, or discard this patch.
Spacing   +258 added lines, -258 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2
-define("ENCRYPTPTION_STORAGE_MODE","InstructionFile");
2
+define("ENCRYPTPTION_STORAGE_MODE", "InstructionFile");
3 3
 require_once "../encryption/EncryptionUtil.php";
4 4
 require_once "../Ks3Client.class.php";
5 5
 require_once "../Ks3EncryptionClient.class.php";
6 6
 require_once "TestUtil.php";
7 7
 require_once "PUnit.php";
8 8
 require_once "../lib/RequestCore.class.php";
9
-class SDKTest extends PUnit{
9
+class SDKTest extends PUnit {
10 10
 	protected $bucket = "php-sdk-test";
11 11
 	protected $key = "test==中/文?";
12 12
 	protected $key_copy = "test中/文_copy?";
@@ -16,64 +16,64 @@  discard block
 block discarded – undo
16 16
     protected $encryptionClient;
17 17
 	protected $cachedir;
18 18
     protected $sseckey;
19
-	public function __construct(){
20
-		$this->client=new Ks3Client($this->accesskey,$this->secrectkey);
21
-		$this->cachedir=KS3_API_PATH.DIRECTORY_SEPARATOR."unit".DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR;
19
+	public function __construct() {
20
+		$this->client = new Ks3Client($this->accesskey, $this->secrectkey);
21
+		$this->cachedir = KS3_API_PATH.DIRECTORY_SEPARATOR."unit".DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR;
22 22
         $filename = "secret.key";
23 23
         $handle = fopen($filename, "r");
24
-        $sseckey = fread($handle, filesize ($filename));
24
+        $sseckey = fread($handle, filesize($filename));
25 25
         fclose($handle);
26 26
         $this->sseckey = $sseckey;
27
-        $this->encryptionClient = new Ks3EncryptionClient($this->accesskey,$this->secrectkey,$sseckey);
27
+        $this->encryptionClient = new Ks3EncryptionClient($this->accesskey, $this->secrectkey, $sseckey);
28 28
 	}
29
-	public function before(){
30
-		if($this->client->bucketExists(array("Bucket"=>$this->bucket))){
29
+	public function before() {
30
+		if ($this->client->bucketExists(array("Bucket"=>$this->bucket))) {
31 31
 			$keys = array();
32 32
 			$objects = $this->client->listObjects(array("Bucket"=>$this->bucket));
33 33
 			foreach ($objects["Contents"] as $object) {
34 34
 				array_push($keys, $object["Key"]);
35 35
 			}
36
-			$this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>$keys));
37
-		}else{
36
+			$this->client->deleteObjects(array("Bucket"=>$this->bucket, "DeleteKeys"=>$keys));
37
+		}else {
38 38
 			$this->client->createBucket(array("Bucket"=>$this->bucket));
39 39
 		}
40 40
 	}
41
-	public function testListBuckets(){
41
+	public function testListBuckets() {
42 42
 		$buckets = $this->client->listBuckets();
43 43
 		$found = FALSE;
44 44
 		foreach ($buckets as $bucket) {
45
-			if($bucket["Name"] == $this->bucket)
45
+			if ($bucket["Name"] == $this->bucket)
46 46
 				$found = TRUE;
47 47
 		}
48
-		if(!$found)
48
+		if (!$found)
49 49
 			throw new Exception("list buckets expected found ".$this->bucket.",but not found");
50 50
 			
51 51
 	}
52
-	public function testDeleteBucket(){
53
-		$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>"test","Content"=>""));
52
+	public function testDeleteBucket() {
53
+		$this->client->putObjectByContent(array("Bucket"=>$this->bucket, "Key"=>"test", "Content"=>""));
54 54
 		$ex = NULL;
55
-		try{
55
+		try {
56 56
 			$this->client->deleteBucket(array("Bucket"=>$this->bucket));
57
-		}catch(Exception $e){
57
+		} catch (Exception $e) {
58 58
 			$ex = $e;
59 59
 		}
60
-		if($ex == NULL||!($ex->errorCode === "BucketNotEmpty")){
60
+		if ($ex == NULL || !($ex->errorCode === "BucketNotEmpty")) {
61 61
 			throw new Exception("delete bucket expected BucketNotEmpty but ".$ex);
62 62
 		}
63 63
 	}
64
-	public function testBucketCORS(){
64
+	public function testBucketCORS() {
65 65
 		$this->client->setBucketCORS($args = array(
66 66
        		"Bucket"=>$this->bucket,
67 67
         	"CORS"=>array(
68 68
         		array(
69
-           			"AllowedMethod"=>array("GET","PUT"),
69
+           			"AllowedMethod"=>array("GET", "PUT"),
70 70
             		"AllowedOrigin"=>array("http://www.kingsoft.com"),
71 71
             		"AllowedHeader"=>array("*"),
72 72
             		"ExposeHeader"=>array("*"),
73 73
             		"MaxAgeSeconds"=>10
74 74
         		),
75 75
         		array(
76
-         		  "AllowedMethod"=>array("GET","PUT"),
76
+         		  "AllowedMethod"=>array("GET", "PUT"),
77 77
           		  "AllowedOrigin"=>array("*"),
78 78
           		  "AllowedHeader"=>array("*"),
79 79
           		  "ExposeHeader"=>array("*"),
@@ -81,28 +81,28 @@  discard block
 block discarded – undo
81 81
         		)
82 82
     		)));
83 83
  	    $cors = $this->client->getBucketCORS(array("Bucket"=>$this->bucket));
84
- 	    $this->assertEquals(count($cors),2,"bucket cors count ");
84
+ 	    $this->assertEquals(count($cors), 2, "bucket cors count ");
85 85
    		$this->client->deleteBucketCORS(array("Bucket"=>$this->bucket));
86 86
    		$cors = $this->client->getBucketCORS(array("Bucket"=>$this->bucket));
87
-		$this->assertEquals(count($cors),0,"bucket cors count ");
87
+		$this->assertEquals(count($cors), 0, "bucket cors count ");
88 88
 	}
89
-	public function testCreateBucket(){
89
+	public function testCreateBucket() {
90 90
 		$ex = NULL;
91
-		try{
91
+		try {
92 92
 			$this->client->createBucket(array("Bucket"=>$this->bucket));
93
-		}catch(Exception $e){
93
+		} catch (Exception $e) {
94 94
 			$ex = $e;
95 95
 		}
96
-		if($ex == NULL||!($ex->errorCode === "BucketAlreadyExists")){
96
+		if ($ex == NULL || !($ex->errorCode === "BucketAlreadyExists")) {
97 97
 			throw new Exception("create bucket expected BucketAlreadyExists but ".$ex);
98 98
 		}
99 99
 	}
100
-	public function testACL(){
101
-		$this->client->setBucketAcl(array("Bucket"=>$this->bucket,"ACL"=>"public-read"));
100
+	public function testACL() {
101
+		$this->client->setBucketAcl(array("Bucket"=>$this->bucket, "ACL"=>"public-read"));
102 102
 		$acl = $this->client->getBucketAcl(array("Bucket"=>$this->bucket));
103
-		$this->assertEquals($acl,"public-read","bucket acl");
103
+		$this->assertEquals($acl, "public-read", "bucket acl");
104 104
 	}
105
-	public function testBucketLogging(){
105
+	public function testBucketLogging() {
106 106
 		$this->client->setBucketLogging(array(
107 107
         	"Bucket"=>$this->bucket,
108 108
         	"BucketLogging"=>array(
@@ -112,27 +112,27 @@  discard block
 block discarded – undo
112 112
             )
113 113
         ));
114 114
     	$logging = $this->client->getBucketLogging(array("Bucket"=>$this->bucket));
115
-    	$this->assertEquals($logging["Enable"],TRUE,"bucket logging enable");
115
+    	$this->assertEquals($logging["Enable"], TRUE, "bucket logging enable");
116 116
 
117 117
     	$this->client->setBucketLogging(array(
118 118
     		"Bucket"=>$this->bucket,
119 119
     		"BucketLogging"=>array(
120
-        		"Enable"=>FALSE,//是否开启
120
+        		"Enable"=>FALSE, //是否开启
121 121
         	)
122 122
     	));
123 123
     	$logging = $this->client->getBucketLogging(array("Bucket"=>$this->bucket));
124
-    	$this->assertEquals($logging["Enable"],FALSE,"bucket logging enable");
124
+    	$this->assertEquals($logging["Enable"], FALSE, "bucket logging enable");
125 125
 	}
126
-	public function testBucketLocation(){
126
+	public function testBucketLocation() {
127 127
 		$location = $this->client->getBucketLocation(array("Bucket"=>$this->bucket));
128
-		$this->assertEquals($location,"HANGZHOU","bucket location ");
128
+		$this->assertEquals($location, "HANGZHOU", "bucket location ");
129 129
 	}
130
-	public function testPutObjectByContentAndGetObjectContent(){
130
+	public function testPutObjectByContentAndGetObjectContent() {
131 131
 		$args = array(
132 132
         	"Bucket"=>$this->bucket,
133 133
         	"Key"=>$this->key,
134
-        	"Content"=>"1234",//要上传的内容
135
-        	"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
134
+        	"Content"=>"1234", //要上传的内容
135
+        	"ACL"=>"public-read", //可以设置访问权限,合法值,private、public-read
136 136
         	"ObjectMeta"=>array(
137 137
             	"Content-Type"=>"application/xml",
138 138
             	"Content-Length"=>3
@@ -142,29 +142,29 @@  discard block
 block discarded – undo
142 142
             )
143 143
         );
144 144
         $this->client->putObjectByContent($args);
145
-        $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),TRUE,"object exists ");
146
-        $meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket,"Key"=>$this->key));
147
-        $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"],"test","x-kss-meta-test");
148
-        $this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type");
149
-        $this->assertEquals($meta["ObjectMeta"]["Content-Length"],3,"Content-Length");
150
-        $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl ");
145
+        $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket, "Key"=>$this->key)), TRUE, "object exists ");
146
+        $meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket, "Key"=>$this->key));
147
+        $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"], "test", "x-kss-meta-test");
148
+        $this->assertEquals($meta["ObjectMeta"]["Content-Type"], "application/xml", "Content-Type");
149
+        $this->assertEquals($meta["ObjectMeta"]["Content-Length"], 3, "Content-Length");
150
+        $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket, "Key"=>$this->key)), "public-read", "object acl ");
151 151
 
152
-        $s3Object = $this->client->getObject(array("Bucket"=>$this->bucket,"Key"=>$this->key));
153
-        $this->assertEquals($s3Object["Content"],"123","s3 object content");
152
+        $s3Object = $this->client->getObject(array("Bucket"=>$this->bucket, "Key"=>$this->key));
153
+        $this->assertEquals($s3Object["Content"], "123", "s3 object content");
154 154
         $meta = $s3Object["Meta"];
155
-        $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"],"test","x-kss-meta-test");
156
-        $this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type");
157
-        $this->assertEquals($meta["ObjectMeta"]["Content-Length"],3,"Content-Length");
155
+        $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"], "test", "x-kss-meta-test");
156
+        $this->assertEquals($meta["ObjectMeta"]["Content-Type"], "application/xml", "Content-Type");
157
+        $this->assertEquals($meta["ObjectMeta"]["Content-Length"], 3, "Content-Length");
158 158
 
159 159
 	}
160
-	public function testPutObjectByFile(){
160
+	public function testPutObjectByFile() {
161 161
 		$args = array(
162 162
         	"Bucket"=>$this->bucket,
163 163
         	"Key"=>$this->key,
164 164
         	"Content"=>array(
165 165
         		"content"=>$this->cachedir."test_file"
166
-        	),//要上传的内容
167
-        	"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
166
+        	), //要上传的内容
167
+        	"ACL"=>"public-read", //可以设置访问权限,合法值,private、public-read
168 168
         	"ObjectMeta"=>array(
169 169
             	"Content-Type"=>"application/xml",
170 170
             	"Content-Length"=>100
@@ -174,48 +174,48 @@  discard block
 block discarded – undo
174 174
             )
175 175
         );
176 176
         $this->client->putObjectByFile($args);
177
-        $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),TRUE,"object exists ");
178
-        $meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket,"Key"=>$this->key));
179
-        $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"],"test","x-kss-meta-test");
180
-        $this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type");
181
-        $this->assertEquals($meta["ObjectMeta"]["Content-Length"],100,"Content-Length");
182
-        $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl ");
177
+        $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket, "Key"=>$this->key)), TRUE, "object exists ");
178
+        $meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket, "Key"=>$this->key));
179
+        $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"], "test", "x-kss-meta-test");
180
+        $this->assertEquals($meta["ObjectMeta"]["Content-Type"], "application/xml", "Content-Type");
181
+        $this->assertEquals($meta["ObjectMeta"]["Content-Length"], 100, "Content-Length");
182
+        $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket, "Key"=>$this->key)), "public-read", "object acl ");
183 183
 	}
184
-	public function testObjectAcl(){
185
-		$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key,
186
-"Content"=>"1234","ACL"=>"private"));
187
-		$this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"private","object acl");
188
-		$this->client->setObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key,"ACL"=>"public-read"));
189
-		$this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl");
184
+	public function testObjectAcl() {
185
+		$this->client->putObjectByContent(array("Bucket"=>$this->bucket, "Key"=>$this->key,
186
+"Content"=>"1234", "ACL"=>"private"));
187
+		$this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket, "Key"=>$this->key)), "private", "object acl");
188
+		$this->client->setObjectAcl(array("Bucket"=>$this->bucket, "Key"=>$this->key, "ACL"=>"public-read"));
189
+		$this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket, "Key"=>$this->key)), "public-read", "object acl");
190 190
 	}
191
-	public function testDeleteObject(){
192
-		$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key,
191
+	public function testDeleteObject() {
192
+		$this->client->putObjectByContent(array("Bucket"=>$this->bucket, "Key"=>$this->key,
193 193
 "Content"=>"1234"));
194
-		$this->client->deleteObject(array("Bucket"=>$this->bucket,"Key"=>$this->key));
195
-		$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),FALSE,"object exits");
194
+		$this->client->deleteObject(array("Bucket"=>$this->bucket, "Key"=>$this->key));
195
+		$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket, "Key"=>$this->key)), FALSE, "object exits");
196 196
 	}
197
-	public function testDeleteObjects(){
198
-		$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key,
197
+	public function testDeleteObjects() {
198
+		$this->client->putObjectByContent(array("Bucket"=>$this->bucket, "Key"=>$this->key,
199 199
 "Content"=>"1234"));
200
-		$this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>array($this->key)));
201
-		$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),FALSE,"object exits");		
200
+		$this->client->deleteObjects(array("Bucket"=>$this->bucket, "DeleteKeys"=>array($this->key)));
201
+		$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket, "Key"=>$this->key)), FALSE, "object exits");		
202 202
 	}
203
-	public function testCopyObject(){
204
-		$this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key,
203
+	public function testCopyObject() {
204
+		$this->client->putObjectByContent(array("Bucket"=>$this->bucket, "Key"=>$this->key,
205 205
 "Content"=>"1234"));
206
-		$this->client->copyObject(array("Bucket"=>$this->bucket,"Key"=>$this->key_copy,"CopySource"=>array("Bucket"=>$this->bucket,"Key"=>$this->key)));
207
-		$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),TRUE,"object exits");
208
-		$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key_copy)),TRUE
206
+		$this->client->copyObject(array("Bucket"=>$this->bucket, "Key"=>$this->key_copy, "CopySource"=>array("Bucket"=>$this->bucket, "Key"=>$this->key)));
207
+		$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket, "Key"=>$this->key)), TRUE, "object exits");
208
+		$this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket, "Key"=>$this->key_copy)), TRUE
209 209
 			,"object exits");
210 210
 	}
211
-	public function testPutAndGetObject(){
211
+	public function testPutAndGetObject() {
212 212
 		$args = array(
213 213
         	"Bucket"=>$this->bucket,
214 214
         	"Key"=>$this->key,
215 215
         	"Content"=>array(
216 216
         		"content"=>$this->cachedir."test_file"
217
-        	),//要上传的内容
218
-        	"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
217
+        	), //要上传的内容
218
+        	"ACL"=>"public-read", //可以设置访问权限,合法值,private、public-read
219 219
         	"ObjectMeta"=>array(
220 220
             	"Content-Type"=>"application/xml",
221 221
             ),
@@ -224,20 +224,20 @@  discard block
 block discarded – undo
224 224
             )
225 225
         );
226 226
         $this->client->putObjectByFile($args);
227
-        $this->client->getObject(array("Bucket"=>$this->bucket,"Key"=>$this->key,"WriteTo"=>$this->cachedir."down"));
227
+        $this->client->getObject(array("Bucket"=>$this->bucket, "Key"=>$this->key, "WriteTo"=>$this->cachedir."down"));
228 228
         $md5 = md5_file($this->cachedir."down");
229 229
         $md5pre = md5_file($this->cachedir."test_file");
230 230
         @unlink($this->cachedir."down");
231
-        $this->assertEquals($md5,$md5pre,"contentmd5");
231
+        $this->assertEquals($md5, $md5pre, "contentmd5");
232 232
 	}
233
-	public function testPutAndGetObjectRanges(){
233
+	public function testPutAndGetObjectRanges() {
234 234
 		$args = array(
235 235
         	"Bucket"=>$this->bucket,
236 236
         	"Key"=>$this->key,
237 237
         	"Content"=>array(
238 238
         		"content"=>$this->cachedir."test_file"
239
-        	),//要上传的内容
240
-        	"ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
239
+        	), //要上传的内容
240
+        	"ACL"=>"public-read", //可以设置访问权限,合法值,private、public-read
241 241
         	"ObjectMeta"=>array(
242 242
             	"Content-Type"=>"application/xml",
243 243
             ),
@@ -246,25 +246,25 @@  discard block
 block discarded – undo
246 246
             )
247 247
         );
248 248
         $this->client->putObjectByFile($args);
249
-        rangeGetAndCheckMd5($this->client,$this->bucket,$this->key,$this->cachedir."down",md5_file($this->cachedir."test_file"));
249
+        rangeGetAndCheckMd5($this->client, $this->bucket, $this->key, $this->cachedir."down", md5_file($this->cachedir."test_file"));
250 250
 	}
251
-	public function testInitAndAbortMultipart(){
252
-		$initResult = $this->client->initMultipartUpload(array("Bucket"=>$this->bucket,"Key"=>$this->key));
251
+	public function testInitAndAbortMultipart() {
252
+		$initResult = $this->client->initMultipartUpload(array("Bucket"=>$this->bucket, "Key"=>$this->key));
253 253
 		$uid = $initResult["UploadId"];
254
-		$listParts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid)));
255
-		$this->client->abortMultipartUpload(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid)));
254
+		$listParts = $this->client->listParts(array("Bucket"=>$this->bucket, "Key"=>$this->key, "Options"=>array("uploadId"=>$uid)));
255
+		$this->client->abortMultipartUpload(array("Bucket"=>$this->bucket, "Key"=>$this->key, "Options"=>array("uploadId"=>$uid)));
256 256
 		$ex = NULL;
257
-		try{
258
-			$this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid)));
259
-		}catch(Exception $e){
257
+		try {
258
+			$this->client->listParts(array("Bucket"=>$this->bucket, "Key"=>$this->key, "Options"=>array("uploadId"=>$uid)));
259
+		} catch (Exception $e) {
260 260
 			$ex = $e;
261 261
 		}
262
-		if($ex == NULL||!($ex->errorCode === "NoSuchUpload")){
262
+		if ($ex == NULL || !($ex->errorCode === "NoSuchUpload")) {
263 263
 			throw new Exception("create bucket expected NoSuchUpload but ".$ex);
264 264
 		}
265 265
 	}
266
-	public function testMultipartUpload(){
267
-		generateFile(1024*1024,$this->cachedir."multi");
266
+	public function testMultipartUpload() {
267
+		generateFile(1024*1024, $this->cachedir."multi");
268 268
 		//初始化分开上传,获取uploadid
269 269
         $args = array(
270 270
             "Bucket"=>$this->bucket,
@@ -278,18 +278,18 @@  discard block
 block discarded – undo
278 278
             )
279 279
         );
280 280
         $uploadid = $this->client->initMultipartUpload($args);
281
-        $uploadid = $uploadid["UploadId"];//获取到uploadid
281
+        $uploadid = $uploadid["UploadId"]; //获取到uploadid
282 282
         //开始上传
283
-        $file = $this->cachedir."multi";//要上传的文件
283
+        $file = $this->cachedir."multi"; //要上传的文件
284 284
         $partsize = 1024*100;
285
-        $resource = fopen($file,"r");
285
+        $resource = fopen($file, "r");
286 286
         $stat = fstat($resource);
287
-        $total = $stat["size"];//获取文件的总大小
287
+        $total = $stat["size"]; //获取文件的总大小
288 288
         fclose($resource);
289
-        $count = (int)(($total-1)/$partsize)+1;;//计算文件需要分几块上传
290
-        for($i = 0;$i < $count;$i++){
289
+        $count = (int)(($total-1)/$partsize)+1; ;//计算文件需要分几块上传
290
+        for ($i = 0; $i < $count; $i++) {
291 291
             //依次上传每一块
292
-            $args=array(
292
+            $args = array(
293 293
                 "Bucket"=>$this->bucket,
294 294
                 "Key"=>$this->key,
295 295
                 "Options"=>array(
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
                     "uploadId"=>$uploadid
298 298
                 ),
299 299
                 "ObjectMeta"=>array(
300
-                    "Content-Length"=>min($partsize,$total-$partsize*$i)//每次上传$partsize大小
300
+                    "Content-Length"=>min($partsize, $total-$partsize*$i)//每次上传$partsize大小
301 301
                 ),
302 302
                 "Content"=>array(
303 303
                     "content"=>$file,
@@ -307,24 +307,24 @@  discard block
 block discarded – undo
307 307
             $etag = $this->client->uploadPart($args);
308 308
             $etag = $etag["ETag"];
309 309
         }
310
-        $parts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uploadid)));
310
+        $parts = $this->client->listParts(array("Bucket"=>$this->bucket, "Key"=>$this->key, "Options"=>array("uploadId"=>$uploadid)));
311 311
         //结束上传
312
-        $args=array(
312
+        $args = array(
313 313
             "Bucket"=>$this->bucket,
314 314
             "Key"=>$this->key,
315 315
             "Options"=>array("uploadId"=>$uploadid),
316 316
             "Parts"=>$parts["Parts"]//使用之前列出的块完成分开上传
317 317
         );
318 318
         $result = $this->client->completeMultipartUpload($args);
319
-        $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl");
320
-        $meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket,"Key"=>$this->key));
321
-        $this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type");
322
-        $this->assertEquals($meta["ObjectMeta"]["Content-Length"],filesize($this->cachedir."multi"),"Content-Length");
323
-        $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"],"example","x-kss-meta-test");
324
-        rangeGetAndCheckMd5($this->client,$this->bucket,$this->key,$this->cachedir."down",md5_file($this->cachedir."multi"));
319
+        $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket, "Key"=>$this->key)), "public-read", "object acl");
320
+        $meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket, "Key"=>$this->key));
321
+        $this->assertEquals($meta["ObjectMeta"]["Content-Type"], "application/xml", "Content-Type");
322
+        $this->assertEquals($meta["ObjectMeta"]["Content-Length"], filesize($this->cachedir."multi"), "Content-Length");
323
+        $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"], "example", "x-kss-meta-test");
324
+        rangeGetAndCheckMd5($this->client, $this->bucket, $this->key, $this->cachedir."down", md5_file($this->cachedir."multi"));
325 325
         @unlink($this->cachedir."multi");
326 326
 	}
327
-	public function testListBucketsPresignedUrl(){
327
+	public function testListBucketsPresignedUrl() {
328 328
 		$url = $this->client->generatePresignedUrl(
329 329
 			array(
330 330
 				"Method"=>"GET",
@@ -333,12 +333,12 @@  discard block
 block discarded – undo
333 333
 				));
334 334
 		$httpRequest = new RequestCore($url);
335 335
 		$httpRequest->set_method("GET");
336
-        $httpRequest->add_header("Content-Type","text/plain");
336
+        $httpRequest->add_header("Content-Type", "text/plain");
337 337
 		$httpRequest->send_request();
338
-		$body = $httpRequest->get_response_body ();	
339
-		$this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"list buckets status code");
338
+		$body = $httpRequest->get_response_body();	
339
+		$this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "list buckets status code");
340 340
 	}
341
-    public function testHeadBucketPresignedUrl(){
341
+    public function testHeadBucketPresignedUrl() {
342 342
         $url = $this->client->generatePresignedUrl(
343 343
             array(
344 344
                 "Method"=>"HEAD",
@@ -349,12 +349,12 @@  discard block
 block discarded – undo
349 349
             );
350 350
         $httpRequest = new RequestCore($url);
351 351
         $httpRequest->set_method("HEAD");
352
-        $httpRequest->add_header("Content-Type","text/plain");
352
+        $httpRequest->add_header("Content-Type", "text/plain");
353 353
         $httpRequest->send_request();
354
-        $body = $httpRequest->get_response_body (); 
355
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"head bucket status code");
354
+        $body = $httpRequest->get_response_body(); 
355
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "head bucket status code");
356 356
     }
357
-    public function testDeleteBucketPresignedUrl(){
357
+    public function testDeleteBucketPresignedUrl() {
358 358
         $this->client->putObjectByContent(array(
359 359
             "Bucket"=>$this->bucket,
360 360
             "Key"=>$this->key,
@@ -371,28 +371,28 @@  discard block
 block discarded – undo
371 371
             );
372 372
         $httpRequest = new RequestCore($url);
373 373
         $httpRequest->set_method("DELETE");
374
-        $httpRequest->add_header("Content-Type","text/plain");
374
+        $httpRequest->add_header("Content-Type", "text/plain");
375 375
         $httpRequest->send_request();
376
-        $body = $httpRequest->get_response_body (); 
377
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,409,"delete bucket status code");      
376
+        $body = $httpRequest->get_response_body(); 
377
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 409, "delete bucket status code");      
378 378
     }
379
-    public function testGetBucketAclPresignedUrl(){
379
+    public function testGetBucketAclPresignedUrl() {
380 380
         $url = $this->client->generatePresignedUrl(
381 381
             array(
382 382
                 "Method"=>"GET",
383 383
                 "Bucket"=>$this->bucket,
384
-                "Options"=>array("Expires"=>60*10,"acl"=>NULL),
384
+                "Options"=>array("Expires"=>60*10, "acl"=>NULL),
385 385
                 "Headers"=>array("Content-Type"=>"text/plain")
386 386
                 )
387 387
             );
388 388
         $httpRequest = new RequestCore($url);
389 389
         $httpRequest->set_method("GET");
390
-        $httpRequest->add_header("Content-Type","text/plain");
390
+        $httpRequest->add_header("Content-Type", "text/plain");
391 391
         $httpRequest->send_request();
392
-        $body = $httpRequest->get_response_body (); 
393
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get bucket acl status code");      
392
+        $body = $httpRequest->get_response_body(); 
393
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "get bucket acl status code");      
394 394
     }
395
-    public function testPutBucketPresignedUrl(){
395
+    public function testPutBucketPresignedUrl() {
396 396
         $url = $this->client->generatePresignedUrl(
397 397
             array(
398 398
                 "Method"=>"PUT",
@@ -403,96 +403,96 @@  discard block
 block discarded – undo
403 403
             );
404 404
         $httpRequest = new RequestCore($url);
405 405
         $httpRequest->set_method("PUT");
406
-        $httpRequest->add_header("Content-Type","text/plain");
406
+        $httpRequest->add_header("Content-Type", "text/plain");
407 407
         $httpRequest->send_request();
408
-        $body = $httpRequest->get_response_body (); 
409
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,409,"delete bucket status code");      
408
+        $body = $httpRequest->get_response_body(); 
409
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 409, "delete bucket status code");      
410 410
     }
411
-    public function testPutBucketAclPresignedUrl(){
411
+    public function testPutBucketAclPresignedUrl() {
412 412
         $url = $this->client->generatePresignedUrl(
413 413
             array(
414 414
                 "Method"=>"PUT",
415 415
                 "Bucket"=>$this->bucket,
416
-                "Options"=>array("Expires"=>60*10,"acl"=>NULL),
417
-                "Headers"=>array("Content-Type"=>"text/plain","x-kss-acl"=>"public-read")
416
+                "Options"=>array("Expires"=>60*10, "acl"=>NULL),
417
+                "Headers"=>array("Content-Type"=>"text/plain", "x-kss-acl"=>"public-read")
418 418
                 )
419 419
             );
420 420
         $httpRequest = new RequestCore($url);
421 421
         $httpRequest->set_method("PUT");
422
-        $httpRequest->add_header("Content-Type","text/plain");
423
-        $httpRequest->add_header("x-kss-acl","public-read");
422
+        $httpRequest->add_header("Content-Type", "text/plain");
423
+        $httpRequest->add_header("x-kss-acl", "public-read");
424 424
         $httpRequest->send_request();
425
-        $body = $httpRequest->get_response_body (); 
426
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"put bucket acl status code"); 
427
-        $this->assertEquals($this->client->getBucketAcl(array("Bucket"=>$this->bucket)),"public-read","bucket acl");
425
+        $body = $httpRequest->get_response_body(); 
426
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "put bucket acl status code"); 
427
+        $this->assertEquals($this->client->getBucketAcl(array("Bucket"=>$this->bucket)), "public-read", "bucket acl");
428 428
     }
429
-    public function testListObjectsPresignedUrl(){
429
+    public function testListObjectsPresignedUrl() {
430 430
         $url = $this->client->generatePresignedUrl(array(
431 431
             "Method"=>"GET",
432 432
             "Bucket"=>$this->bucket,
433
-            "Options"=>array("Expires"=>60*10,"delimiter"=>"/"),
433
+            "Options"=>array("Expires"=>60*10, "delimiter"=>"/"),
434 434
             "Headers"=>array("Content-Type"=>"text/plain")
435 435
             )
436 436
         );
437 437
         $httpRequest = new RequestCore($url);
438 438
         $httpRequest->set_method("GET");
439
-        $httpRequest->add_header("Content-Type","text/plain");
439
+        $httpRequest->add_header("Content-Type", "text/plain");
440 440
         $httpRequest->send_request();
441
-        $body = $httpRequest->get_response_body (); 
442
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"list objects status code"); 
441
+        $body = $httpRequest->get_response_body(); 
442
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "list objects status code"); 
443 443
     }
444
-    public function testGetBucketLoggingPresignedUrl(){
444
+    public function testGetBucketLoggingPresignedUrl() {
445 445
         $url = $this->client->generatePresignedUrl(array(
446 446
             "Method"=>"GET",
447 447
             "Bucket"=>$this->bucket,
448
-            "Options"=>array("Expires"=>60*10,"logging"=>""),
448
+            "Options"=>array("Expires"=>60*10, "logging"=>""),
449 449
             "Headers"=>array("Content-Type"=>"text/plain")
450 450
             )
451 451
         );
452 452
         $httpRequest = new RequestCore($url);
453 453
         $httpRequest->set_method("GET");
454
-        $httpRequest->add_header("Content-Type","text/plain");
454
+        $httpRequest->add_header("Content-Type", "text/plain");
455 455
         $httpRequest->send_request();
456
-        $body = $httpRequest->get_response_body (); 
457
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get bucket logging status code"); 
456
+        $body = $httpRequest->get_response_body(); 
457
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "get bucket logging status code"); 
458 458
     }
459
-    public function testPutBucketLoggingPresignedUrl(){
459
+    public function testPutBucketLoggingPresignedUrl() {
460 460
         $xml = new SimpleXmlElement('<BucketLoggingStatus xmlns="http://s3.amazonaws.com/doc/2006-03-01/" />');
461 461
         $xml = $xml->asXml();
462 462
         $url = $this->client->generatePresignedUrl(
463 463
             array(
464 464
                 "Method"=>"PUT",
465 465
                 "Bucket"=>$this->bucket,
466
-                "Options"=>array("Expires"=>60*10,"logging"=>NULL),
466
+                "Options"=>array("Expires"=>60*10, "logging"=>NULL),
467 467
                 "Headers"=>array("Content-Type"=>"application/xml")
468 468
             )
469 469
         );
470 470
         $httpRequest = new RequestCore($url);
471 471
         $httpRequest->set_method("PUT");
472
-        $httpRequest->add_header("Content-Type","application/xml");
473
-        $httpRequest->add_header("Content-Length",strlen($xml));
474
-        $httpRequest->request_body=$xml;
472
+        $httpRequest->add_header("Content-Type", "application/xml");
473
+        $httpRequest->add_header("Content-Length", strlen($xml));
474
+        $httpRequest->request_body = $xml;
475 475
         $httpRequest->send_request();
476
-        $body = $httpRequest->get_response_body (); 
477
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"put bucket logging status code"); 
476
+        $body = $httpRequest->get_response_body(); 
477
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "put bucket logging status code"); 
478 478
     }
479
-    public function testGetBucketLocationPresignedUrl(){
479
+    public function testGetBucketLocationPresignedUrl() {
480 480
         $url = $this->client->generatePresignedUrl(
481 481
             array(
482 482
                 "Method"=>"GET",
483 483
                 "Bucket"=>$this->bucket,
484
-                "Options"=>array("Expires"=>60*10,"location"=>NULL),
484
+                "Options"=>array("Expires"=>60*10, "location"=>NULL),
485 485
                 "Headers"=>array("Content-Type"=>"text/plain")
486 486
             )
487 487
         );
488 488
         $httpRequest = new RequestCore($url);
489 489
         $httpRequest->set_method("GET");
490
-        $httpRequest->add_header("Content-Type","text/plain");
490
+        $httpRequest->add_header("Content-Type", "text/plain");
491 491
         $httpRequest->send_request();
492
-        $body = $httpRequest->get_response_body (); 
493
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get bucket location status code"); 
492
+        $body = $httpRequest->get_response_body(); 
493
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "get bucket location status code"); 
494 494
     }
495
-    public function testDeleteObjectPresignedUrl(){
495
+    public function testDeleteObjectPresignedUrl() {
496 496
         $this->client->putObjectByContent(array(
497 497
             "Bucket"=>$this->bucket,
498 498
             "Key"=>$this->key,
@@ -510,12 +510,12 @@  discard block
 block discarded – undo
510 510
         );
511 511
         $httpRequest = new RequestCore($url);
512 512
         $httpRequest->set_method("DELETE");
513
-        $httpRequest->add_header("Content-Type","text/plain");
513
+        $httpRequest->add_header("Content-Type", "text/plain");
514 514
         $httpRequest->send_request();
515
-        $body = $httpRequest->get_response_body (); 
516
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,204,"delete object status code"); 
515
+        $body = $httpRequest->get_response_body(); 
516
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 204, "delete object status code"); 
517 517
     }
518
-    public function testGetObjectPresignedUrl(){
518
+    public function testGetObjectPresignedUrl() {
519 519
         $this->client->putObjectByContent(array(
520 520
             "Bucket"=>$this->bucket,
521 521
             "Key"=>$this->key,
@@ -532,13 +532,13 @@  discard block
 block discarded – undo
532 532
         );
533 533
         $httpRequest = new RequestCore($url);
534 534
         $httpRequest->set_method("GET");
535
-        $httpRequest->add_header("Content-Type","text/plain");
535
+        $httpRequest->add_header("Content-Type", "text/plain");
536 536
         $httpRequest->send_request();
537
-        $body = $httpRequest->get_response_body (); 
538
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get object status code"); 
539
-        $this->assertEquals($body,"123","get object body"); 
537
+        $body = $httpRequest->get_response_body(); 
538
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "get object status code"); 
539
+        $this->assertEquals($body, "123", "get object body"); 
540 540
     }
541
-    public function testPutObjectPresignedUrl(){
541
+    public function testPutObjectPresignedUrl() {
542 542
         $body = "123";
543 543
         $url = $this->client->generatePresignedUrl(
544 544
             array(
@@ -551,14 +551,14 @@  discard block
 block discarded – undo
551 551
         );
552 552
         $httpRequest = new RequestCore($url);
553 553
         $httpRequest->set_method("PUT");
554
-        $httpRequest->add_header("Content-Type","application/ocet-stream");
555
-        $httpRequest->add_header("Content-Length",strlen($body));
556
-        $httpRequest->request_body=$body;
554
+        $httpRequest->add_header("Content-Type", "application/ocet-stream");
555
+        $httpRequest->add_header("Content-Length", strlen($body));
556
+        $httpRequest->request_body = $body;
557 557
         $httpRequest->send_request();
558
-        $body = $httpRequest->get_response_body (); 
559
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"put object status code"); 
558
+        $body = $httpRequest->get_response_body(); 
559
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "put object status code"); 
560 560
     }
561
-    public function testHeadObjectPresignedUrl(){
561
+    public function testHeadObjectPresignedUrl() {
562 562
         $this->testPutObjectPresignedUrl();
563 563
         $url = $this->client->generatePresignedUrl(
564 564
             array(
@@ -571,54 +571,54 @@  discard block
 block discarded – undo
571 571
         );
572 572
         $httpRequest = new RequestCore($url);
573 573
         $httpRequest->set_method("HEAD");
574
-        $httpRequest->add_header("Content-Type","text/plain");
574
+        $httpRequest->add_header("Content-Type", "text/plain");
575 575
         $httpRequest->send_request();
576
-        $body = $httpRequest->get_response_body (); 
577
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"head object status code"); 
576
+        $body = $httpRequest->get_response_body(); 
577
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "head object status code"); 
578 578
     }
579
-    public function testGetObjectAclPresignedUrl(){
579
+    public function testGetObjectAclPresignedUrl() {
580 580
         $this->testPutObjectPresignedUrl();
581 581
         $url = $this->client->generatePresignedUrl(
582 582
             array(
583 583
                 "Method"=>"GET",
584 584
                 "Bucket"=>$this->bucket,
585 585
                 "Key"=>$this->key,
586
-                "Options"=>array("Expires"=>60*10,"acl"=>NULL),
586
+                "Options"=>array("Expires"=>60*10, "acl"=>NULL),
587 587
                 "Headers"=>array("Content-Type"=>"text/plain")
588 588
             )
589 589
         );
590 590
         $httpRequest = new RequestCore($url);
591 591
         $httpRequest->set_method("GET");
592
-        $httpRequest->add_header("Content-Type","text/plain");
592
+        $httpRequest->add_header("Content-Type", "text/plain");
593 593
         $httpRequest->send_request();
594
-        $body = $httpRequest->get_response_body (); 
595
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get object acl status code");         
594
+        $body = $httpRequest->get_response_body(); 
595
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "get object acl status code");         
596 596
     }
597
-    public function testPutObjectAclPresignedUrl(){
597
+    public function testPutObjectAclPresignedUrl() {
598 598
         $this->testPutObjectPresignedUrl();
599 599
         $url = $this->client->generatePresignedUrl(
600 600
             array(
601 601
                 "Method"=>"PUT",
602 602
                 "Bucket"=>$this->bucket,
603 603
                 "Key"=>$this->key,
604
-                "Options"=>array("Expires"=>60*10,"acl"=>NULL),
605
-                "Headers"=>array("Content-Type"=>"text/plain","x-kss-acl"=>"public-read")
604
+                "Options"=>array("Expires"=>60*10, "acl"=>NULL),
605
+                "Headers"=>array("Content-Type"=>"text/plain", "x-kss-acl"=>"public-read")
606 606
             )
607 607
         );
608 608
         $httpRequest = new RequestCore($url);
609 609
         $httpRequest->set_method("PUT");
610
-        $httpRequest->add_header("Content-Type","text/plain");
611
-        $httpRequest->add_header("x-kss-acl","public-read");
610
+        $httpRequest->add_header("Content-Type", "text/plain");
611
+        $httpRequest->add_header("x-kss-acl", "public-read");
612 612
         $httpRequest->send_request();
613
-        $body = $httpRequest->get_response_body (); 
614
-        $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"put object acl status code");         
613
+        $body = $httpRequest->get_response_body(); 
614
+        $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "put object acl status code");         
615 615
     }
616
-    public function testPutObjectSSEAndGetHeadObject(){
616
+    public function testPutObjectSSEAndGetHeadObject() {
617 617
         $args = array(
618 618
             "Bucket"=>$this->bucket,
619 619
             "Key"=>$this->key,
620
-            "Content"=>"12345",//要上传的内容
621
-             "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
620
+            "Content"=>"12345", //要上传的内容
621
+             "ACL"=>"public-read", //可以设置访问权限,合法值,private、public-read
622 622
              "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。
623 623
                 "Content-Type"=>"binay/ocet-stream"
624 624
             ),
@@ -630,22 +630,22 @@  discard block
 block discarded – undo
630 630
              )
631 631
         );
632 632
         $result = $this->client->putObjectByContent($args);
633
-        $this->assertEquals($result["SSEAlgm"],"AES256");
633
+        $this->assertEquals($result["SSEAlgm"], "AES256");
634 634
 
635 635
         $args = array(
636 636
             "Bucket"=>$this->bucket,
637 637
             "Key"=>$this->key
638 638
             );
639 639
         $result = $this->client->getObjectMeta($args);
640
-        $this->assertEquals($result["ObjectMeta"]["SSEAlgm"],"AES256");
641
-        rangeGetAndCheckMd5($this->client,$this->bucket,$this->key,$this->cachedir."down",md5("12345"));
640
+        $this->assertEquals($result["ObjectMeta"]["SSEAlgm"], "AES256");
641
+        rangeGetAndCheckMd5($this->client, $this->bucket, $this->key, $this->cachedir."down", md5("12345"));
642 642
     }
643
-    public function testPutObjectSSECAndGetHeadObject(){
643
+    public function testPutObjectSSECAndGetHeadObject() {
644 644
         $args = array(
645 645
             "Bucket"=>$this->bucket,
646 646
             "Key"=>$this->key,
647
-            "Content"=>"12345",//要上传的内容
648
-             "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
647
+            "Content"=>"12345", //要上传的内容
648
+             "ACL"=>"public-read", //可以设置访问权限,合法值,private、public-read
649 649
              "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。
650 650
                 "Content-Type"=>"binay/ocet-stream"
651 651
             ),
@@ -657,8 +657,8 @@  discard block
 block discarded – undo
657 657
              )
658 658
         );
659 659
         $result = $this->client->putObjectByContent($args);
660
-        $this->assertEquals($result["SSECAlgm"],"AES256");
661
-        $this->assertEquals($result["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey)));
660
+        $this->assertEquals($result["SSECAlgm"], "AES256");
661
+        $this->assertEquals($result["SSECKeyMD5"], Utils::hex_to_base64(md5($this->sseckey)));
662 662
 
663 663
         $args = array(
664 664
             "Bucket"=>$this->bucket,
@@ -668,8 +668,8 @@  discard block
 block discarded – undo
668 668
              )
669 669
             );
670 670
         $result = $this->client->getObjectMeta($args);
671
-        $this->assertEquals($result["ObjectMeta"]["SSECAlgm"],"AES256");
672
-        $this->assertEquals($result["ObjectMeta"]["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey)));
671
+        $this->assertEquals($result["ObjectMeta"]["SSECAlgm"], "AES256");
672
+        $this->assertEquals($result["ObjectMeta"]["SSECKeyMD5"], Utils::hex_to_base64(md5($this->sseckey)));
673 673
 
674 674
         $args = array(
675 675
             "Bucket"=>$this->bucket,
@@ -680,10 +680,10 @@  discard block
 block discarded – undo
680 680
              )
681 681
         );
682 682
         $this->client->getObject($args);
683
-        $this->assertEquals("12345",file_get_contents($this->cachedir."down"));
683
+        $this->assertEquals("12345", file_get_contents($this->cachedir."down"));
684 684
         @unlink($this->cachedir."down");
685 685
     }
686
-    public function testMultipartUploadSSE(){
686
+    public function testMultipartUploadSSE() {
687 687
         $file = $this->cachedir."test_file";
688 688
         $args = array(
689 689
             "Bucket"=>$this->bucket,
@@ -694,11 +694,11 @@  discard block
 block discarded – undo
694 694
         );
695 695
         $uploadid = $this->client->initMultipartUpload($args);
696 696
 
697
-        $this->assertEquals($uploadid["SSEAlgm"],"AES256");
697
+        $this->assertEquals($uploadid["SSEAlgm"], "AES256");
698 698
 
699 699
         $uploadid = $uploadid["UploadId"];
700 700
         //开始上传
701
-        $args=array(
701
+        $args = array(
702 702
             "Bucket"=>$this->bucket,
703 703
             "Key"=>$this->key,
704 704
             "Options"=>array(
@@ -711,21 +711,21 @@  discard block
 block discarded – undo
711 711
             );
712 712
         $etag = $this->client->uploadPart($args);
713 713
 
714
-        $this->assertEquals($etag["SSEAlgm"],"AES256");
714
+        $this->assertEquals($etag["SSEAlgm"], "AES256");
715 715
         $etag = $etag["ETag"];
716 716
 
717
-        $parts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uploadid)));
717
+        $parts = $this->client->listParts(array("Bucket"=>$this->bucket, "Key"=>$this->key, "Options"=>array("uploadId"=>$uploadid)));
718 718
         //结束上传
719
-        $args=array(
719
+        $args = array(
720 720
             "Bucket"=>$this->bucket,
721 721
             "Key"=>$this->key,
722 722
             "Options"=>array("uploadId"=>$uploadid),
723 723
             "Parts"=>$parts["Parts"],
724 724
         );
725 725
         $result = $this->client->completeMultipartUpload($args);
726
-        $this->assertEquals($result["SSEAlgm"],"AES256");
726
+        $this->assertEquals($result["SSEAlgm"], "AES256");
727 727
     }
728
-    public function testMultipartUploadSSEC(){
728
+    public function testMultipartUploadSSEC() {
729 729
         $file = $this->cachedir."test_file";
730 730
         $args = array(
731 731
             "Bucket"=>$this->bucket,
@@ -736,12 +736,12 @@  discard block
 block discarded – undo
736 736
         );
737 737
         $uploadid = $this->client->initMultipartUpload($args);
738 738
 
739
-        $this->assertEquals($uploadid["SSECAlgm"],"AES256");
740
-        $this->assertEquals($uploadid["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey)));
739
+        $this->assertEquals($uploadid["SSECAlgm"], "AES256");
740
+        $this->assertEquals($uploadid["SSECKeyMD5"], Utils::hex_to_base64(md5($this->sseckey)));
741 741
 
742 742
         $uploadid = $uploadid["UploadId"];
743 743
         //开始上传
744
-        $args=array(
744
+        $args = array(
745 745
             "Bucket"=>$this->bucket,
746 746
             "Key"=>$this->key,
747 747
             "Options"=>array(
@@ -757,29 +757,29 @@  discard block
 block discarded – undo
757 757
             );
758 758
         $etag = $this->client->uploadPart($args);
759 759
 
760
-        $this->assertEquals($etag["SSECAlgm"],"AES256");
761
-        $this->assertEquals($etag["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey)));
760
+        $this->assertEquals($etag["SSECAlgm"], "AES256");
761
+        $this->assertEquals($etag["SSECKeyMD5"], Utils::hex_to_base64(md5($this->sseckey)));
762 762
 
763 763
         $etag = $etag["ETag"];
764 764
 
765
-        $parts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uploadid)));
765
+        $parts = $this->client->listParts(array("Bucket"=>$this->bucket, "Key"=>$this->key, "Options"=>array("uploadId"=>$uploadid)));
766 766
         //结束上传
767
-        $args=array(
767
+        $args = array(
768 768
             "Bucket"=>$this->bucket,
769 769
             "Key"=>$this->key,
770 770
             "Options"=>array("uploadId"=>$uploadid),
771 771
             "Parts"=>$parts["Parts"],
772 772
         );
773 773
         $result = $this->client->completeMultipartUpload($args);
774
-        $this->assertEquals($result["SSECAlgm"],"AES256");
775
-        $this->assertEquals($result["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey)));
774
+        $this->assertEquals($result["SSECAlgm"], "AES256");
775
+        $this->assertEquals($result["SSECKeyMD5"], Utils::hex_to_base64(md5($this->sseckey)));
776 776
     }
777
-    public function testCopySSECObject(){
777
+    public function testCopySSECObject() {
778 778
         $args = array(
779 779
             "Bucket"=>$this->bucket,
780 780
             "Key"=>$this->key,
781
-            "Content"=>"12345",//要上传的内容
782
-             "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read
781
+            "Content"=>"12345", //要上传的内容
782
+             "ACL"=>"public-read", //可以设置访问权限,合法值,private、public-read
783 783
              "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。
784 784
                 "Content-Type"=>"binay/ocet-stream"
785 785
             ),
@@ -808,8 +808,8 @@  discard block
 block discarded – undo
808 808
             );
809 809
         $result = $this->client->copyObject($args);
810 810
     }
811
-    public function testPutObjectByContentAndGetObjectUsingEncyptionMeta(){
812
-        for($i = 45 ;$i < 60;$i++){
811
+    public function testPutObjectByContentAndGetObjectUsingEncyptionMeta() {
812
+        for ($i = 45; $i < 60; $i++) {
813 813
 
814 814
             $content = EncryptionUtil::genereateOnceUsedKey($i);
815 815
 
@@ -820,11 +820,11 @@  discard block
 block discarded – undo
820 820
                 "Content"=>$content
821 821
             );
822 822
             $this->encryptionClient->putObjectByContent($args);
823
-            rangeGetAndCheckMd5($this->encryptionClient,$this->bucket,$this->key,
824
-               $this->cachedir."down",md5($args["Content"]));
823
+            rangeGetAndCheckMd5($this->encryptionClient, $this->bucket, $this->key,
824
+               $this->cachedir."down", md5($args["Content"]));
825 825
         }
826 826
     }
827
-    public function testPutObjectByFileAndGetObjectUsingEncyptionMeta(){
827
+    public function testPutObjectByFileAndGetObjectUsingEncyptionMeta() {
828 828
         $args = array(
829 829
             "Bucket"=>$this->bucket,
830 830
             "Key"=>$this->key,
@@ -834,40 +834,40 @@  discard block
 block discarded – undo
834 834
             )
835 835
         );
836 836
         $this->encryptionClient->putObjectByFile($args);
837
-        rangeGetAndCheckMd5($this->encryptionClient,$this->bucket,$this->key,
838
-               $this->cachedir."down",md5_file($this->cachedir."test_file"));
837
+        rangeGetAndCheckMd5($this->encryptionClient, $this->bucket, $this->key,
838
+               $this->cachedir."down", md5_file($this->cachedir."test_file"));
839 839
     }
840
-    public function testMultipartUploadUsingEncyptionMeta(){
841
-        generateFile(1024*1024,$this->cachedir."multi");
840
+    public function testMultipartUploadUsingEncyptionMeta() {
841
+        generateFile(1024*1024, $this->cachedir."multi");
842 842
         //初始化分开上传,获取uploadid
843 843
         $args = array(
844 844
             "Bucket"=>$this->bucket,
845 845
             "Key"=>$this->key,
846 846
         );
847 847
         $uploadid = $this->encryptionClient->initMultipartUpload($args);
848
-        $uploadid = $uploadid["UploadId"];//获取到uploadid
848
+        $uploadid = $uploadid["UploadId"]; //获取到uploadid
849 849
         //开始上传
850 850
 
851
-        $file = $this->cachedir."multi";//要上传的文件
851
+        $file = $this->cachedir."multi"; //要上传的文件
852 852
         $partsize = 1024*100;
853
-        $resource = fopen($file,"r");
853
+        $resource = fopen($file, "r");
854 854
         $stat = fstat($resource);
855
-        $total = $stat["size"];//获取文件的总大小
855
+        $total = $stat["size"]; //获取文件的总大小
856 856
         fclose($resource);
857
-        $count = (int)(($total-1)/$partsize)+1;//计算文件需要分几块上传
858
-        for($i = 0;$i < $count;$i++){
857
+        $count = (int)(($total-1)/$partsize)+1; //计算文件需要分几块上传
858
+        for ($i = 0; $i < $count; $i++) {
859 859
             //依次上传每一块
860 860
             echo "upload".$i."\r\n";
861
-            $args=array(
861
+            $args = array(
862 862
                 "Bucket"=>$this->bucket,
863 863
                 "Key"=>$this->key,
864
-                "LastPart"=>($i===$count-1),
864
+                "LastPart"=>($i === $count-1),
865 865
                 "Options"=>array(
866 866
                     "partNumber"=>$i+1,
867 867
                     "uploadId"=>$uploadid
868 868
                 ),
869 869
                 "ObjectMeta"=>array(
870
-                    "Content-Length"=>min($partsize,$total-$partsize*$i)//每次上传$partsize大小
870
+                    "Content-Length"=>min($partsize, $total-$partsize*$i)//每次上传$partsize大小
871 871
                 ),
872 872
                 "Content"=>array(
873 873
                     "content"=>$file,
@@ -877,9 +877,9 @@  discard block
 block discarded – undo
877 877
             $etag = $this->encryptionClient->uploadPart($args);
878 878
             $etag = $etag["ETag"];
879 879
         }
880
-        $parts = $this->encryptionClient->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uploadid)));
880
+        $parts = $this->encryptionClient->listParts(array("Bucket"=>$this->bucket, "Key"=>$this->key, "Options"=>array("uploadId"=>$uploadid)));
881 881
         //结束上传
882
-        $args=array(
882
+        $args = array(
883 883
             "Bucket"=>$this->bucket,
884 884
             "Key"=>$this->key,
885 885
             "Options"=>array("uploadId"=>$uploadid),
@@ -887,11 +887,11 @@  discard block
 block discarded – undo
887 887
         );
888 888
         $result = $this->encryptionClient->completeMultipartUpload($args);
889 889
 
890
-        rangeGetAndCheckMd5($this->encryptionClient,$this->bucket,$this->key,
891
-            $this->cachedir."down",md5_file($file));
890
+        rangeGetAndCheckMd5($this->encryptionClient, $this->bucket, $this->key,
891
+            $this->cachedir."down", md5_file($file));
892 892
         @unlink($this->cachedir."multi");
893 893
     }
894
-    public function testPutObjectByContentAndGetObject(){
894
+    public function testPutObjectByContentAndGetObject() {
895 895
         @unlink($this->cachedir."down");
896 896
         $content = EncryptionUtil::genereateOnceUsedKey(500);
897 897
         $args = array(
@@ -901,15 +901,15 @@  discard block
 block discarded – undo
901 901
             "Content"=>$content
902 902
         );
903 903
         $this->encryptionClient->putObjectByContent($args);
904
-        $start = (int)rand(0,520);
905
-        $end = (int)rand($start,520);
904
+        $start = (int)rand(0, 520);
905
+        $end = (int)rand($start, 520);
906 906
         $s3Object = $this->encryptionClient->getObject(
907
-        array("Bucket"=>$this->bucket,"Key"=>$this->key,
907
+        array("Bucket"=>$this->bucket, "Key"=>$this->key,
908 908
             "Range"=>"bytes=".$start."-".$end)
909 909
         );
910
-        $this->assertEquals(substr($content,$start,$end-$start+1),$s3Object["Content"]);
910
+        $this->assertEquals(substr($content, $start, $end-$start+1), $s3Object["Content"]);
911 911
     }
912
-    public function test01(){
912
+    public function test01() {
913 913
         $this->client->listObjects(array("Bucket"=>$this->bucket));
914 914
     }
915 915
 }
Please login to merge, or discard this patch.
Braces   +10 added lines, -8 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 				array_push($keys, $object["Key"]);
35 35
 			}
36 36
 			$this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>$keys));
37
-		}else{
37
+		} else{
38 38
 			$this->client->createBucket(array("Bucket"=>$this->bucket));
39 39
 		}
40 40
 	}
@@ -42,11 +42,13 @@  discard block
 block discarded – undo
42 42
 		$buckets = $this->client->listBuckets();
43 43
 		$found = FALSE;
44 44
 		foreach ($buckets as $bucket) {
45
-			if($bucket["Name"] == $this->bucket)
46
-				$found = TRUE;
45
+			if($bucket["Name"] == $this->bucket) {
46
+							$found = TRUE;
47
+			}
48
+		}
49
+		if(!$found) {
50
+					throw new Exception("list buckets expected found ".$this->bucket.",but not found");
47 51
 		}
48
-		if(!$found)
49
-			throw new Exception("list buckets expected found ".$this->bucket.",but not found");
50 52
 			
51 53
 	}
52 54
 	public function testDeleteBucket(){
@@ -54,7 +56,7 @@  discard block
 block discarded – undo
54 56
 		$ex = NULL;
55 57
 		try{
56 58
 			$this->client->deleteBucket(array("Bucket"=>$this->bucket));
57
-		}catch(Exception $e){
59
+		} catch(Exception $e){
58 60
 			$ex = $e;
59 61
 		}
60 62
 		if($ex == NULL||!($ex->errorCode === "BucketNotEmpty")){
@@ -90,7 +92,7 @@  discard block
 block discarded – undo
90 92
 		$ex = NULL;
91 93
 		try{
92 94
 			$this->client->createBucket(array("Bucket"=>$this->bucket));
93
-		}catch(Exception $e){
95
+		} catch(Exception $e){
94 96
 			$ex = $e;
95 97
 		}
96 98
 		if($ex == NULL||!($ex->errorCode === "BucketAlreadyExists")){
@@ -256,7 +258,7 @@  discard block
 block discarded – undo
256 258
 		$ex = NULL;
257 259
 		try{
258 260
 			$this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid)));
259
-		}catch(Exception $e){
261
+		} catch(Exception $e){
260 262
 			$ex = $e;
261 263
 		}
262 264
 		if($ex == NULL||!($ex->errorCode === "NoSuchUpload")){
Please login to merge, or discard this patch.