Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions samples/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
}
require_once __DIR__ . '/Config.php';

use OSS\Crypto\BaseCryptoProvider;
use OSS\OssClient;
use Oss\OssEncryptionClient;
use OSS\Core\OssException;
use OSS\Crypto\RsaProvider;
use Oss\Crypto\KmsProvider;

/**
* Class Common
Expand Down Expand Up @@ -39,6 +43,26 @@ public static function getOssClient()
}
return $ossClient;
}


/**
* @param KmsProvider|RsaProvider $provider
* @return OssEncryptionClient|null
*/
public static function getOssEncryptionClient($provider)
{
if (!$provider instanceof BaseCryptoProvider){
throw new OssException('Crypto provider must be an instance of BaseCryptoProvider');
}
try {
$ossClient = new OssEncryptionClient(self::accessKeyId, self::accessKeySecret, self::endpoint, $provider);
} catch (OssException $e) {
printf(__FUNCTION__ . "creating OssClient instance: FAILED\n");
printf($e->getMessage() . "\n");
return null;
}
return $ossClient;
}

public static function getBucketName()
{
Expand Down
3 changes: 3 additions & 0 deletions samples/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ final class Config
const OSS_ACCESS_KEY = 'update me';
const OSS_ENDPOINT = 'update me';
const OSS_TEST_BUCKET = 'update me';
const KMS_ENDPOINT_OTHER = 'update me';
const KMS_ENDPOINT = 'update me';

}
Loading