private function generate($options)
 {
     $bucket = $options[OSSOptions::BUCKET];
     $key = $options[OSSOptions::KEY];
     $method = $options[OSSOptions::METHOD];
     $expires = $options[OSSOptions::EXPIRES];
     $expires = (string) $expires->getTimeStamp();
     $builder = OSSRequestBuilder::factory()->setEndpoint($options[OSSOptions::ENDPOINT])->setBucket($bucket)->setKey($key)->setMethod($method)->addHeader(HttpHeaders::DATE, $expires);
     if (isset($options[OSSOptions::CONTENT_TYPE])) {
         $builder->addHeader(OSSHeaders::CONTENT_TYPE, $options[OSSOptions::CONTENT_TYPE]);
     }
     if (isset($options[OSSOptions::USER_METADATA])) {
         foreach ($options[OSSOptions::USER_METADATA] as $metakey => $value) {
             $builder->addHeader(OSSHeaders::OSS_USER_META_PREFIX . $metakey, $value);
         }
     }
     // Overrides
     $builder->addOverrides($options);
     $request = $builder->build();
     $canonicalString = SignUtils::buildCanonicalString($request, $bucket, $key);
     $signature = ServiceSignature::factory()->computeSignature($options[OSSOptions::ACCESS_KEY_SECRET], $canonicalString);
     $request->addParameter('OSSAccessKeyId', $options[OSSOptions::ACCESS_KEY_ID]);
     $request->addParameter('Signature', $signature);
     $request->addParameter('Expires', $expires);
     return $request->getFullUrl();
 }
 public function sign(HttpRequest $request, array $credentials)
 {
     AssertUtils::assertSet(array(OSSOptions::ACCESS_KEY_ID, OSSOptions::ACCESS_KEY_SECRET), $credentials);
     AssertUtils::assertString($credentials[OSSOptions::ACCESS_KEY_ID], OSSOptions::ACCESS_KEY_ID);
     AssertUtils::assertString($credentials[OSSOptions::ACCESS_KEY_SECRET], OSSOptions::ACCESS_KEY_SECRET);
     $key = $credentials[OSSOptions::ACCESS_KEY_ID];
     $secret = $credentials[OSSOptions::ACCESS_KEY_SECRET];
     if (strlen($key) > 0 && strlen($secret) > 0) {
         $canonicalString = SignUtils::buildCanonicalString($request, $this->bucket, $this->key);
         $signature = ServiceSignature::factory()->computeSignature($secret, $canonicalString);
         $request->addHeader(OSSHeaders::AUTHORIZATION, 'OSS ' . $key . ':' . $signature);
     } else {
         if (strlen($key) > 0) {
             $request->addHeader(OSSHeaders::AUTHORIZATION, $key);
         }
     }
 }