aboutsummaryrefslogtreecommitdiff
path: root/vendor/edu-sharing-plugin/edu-sharing-helper-base.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/edu-sharing-plugin/edu-sharing-helper-base.php')
-rw-r--r--vendor/edu-sharing-plugin/edu-sharing-helper-base.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/vendor/edu-sharing-plugin/edu-sharing-helper-base.php b/vendor/edu-sharing-plugin/edu-sharing-helper-base.php
new file mode 100644
index 0000000..ac3e2f6
--- /dev/null
+++ b/vendor/edu-sharing-plugin/edu-sharing-helper-base.php
@@ -0,0 +1,42 @@
+<?php
+
+class EduSharingHelperBase {
+ public $baseUrl;
+ public $privateKey;
+ public $appId;
+ public $language = 'de';
+
+ /**
+ * @param string $baseUrl
+ * The base url to your repository in the format "http://<host>/edu-sharing"
+ * @param string $privateKey
+ * Your app's private key. This must match the public key registered in the repo
+ * @param string $appId
+ * Your app id name (as registered in the edu-sharing repository)
+ */
+ public function __construct(
+ string $baseUrl,
+ string $privateKey,
+ string $appId
+ ) {
+ if(!preg_match('/^([a-z]|[A-Z]|[0-9]|[-_])+$/', $appId)) {
+ throw new Exception('The given app id contains invalid characters or symbols');
+ }
+ $this->baseUrl=$baseUrl;
+ $this->privateKey=$privateKey;
+ $this->appId=$appId;
+ }
+
+ public function setLanguage(string $language) {
+ $this->language = $language;
+ }
+
+ function sign(string $toSign) {
+ $pkeyid = openssl_get_privatekey($this->privateKey);
+ openssl_sign($toSign, $signature, $pkeyid);
+ $signature = base64_encode($signature);
+ openssl_free_key($pkeyid);
+ return $signature;
+ }
+
+} \ No newline at end of file