Skip to content

Commit edf5f82

Browse files
Merge branch 'master' of https://github.com/paragonie/chronicle
2 parents 22762aa + a145d88 commit edf5f82

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

bin/create-client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119

120120
$db->beginTransaction();
121121
$db->insert(
122-
Chronicle::getTableName('clients', $isSQLite),
122+
Chronicle::getTableNameUnquoted('clients', $isSQLite),
123123
[
124124
'isAdmin' => !empty($admin),
125125
'publicid' => $newPublicId,

bin/replicate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
}
9595

9696
$db->beginTransaction();
97-
$db->insert(Chronicle::getTableName('replication_sources', true), [
97+
$db->insert(Chronicle::getTableNameUnquoted('replication_sources', true), [
9898
'name' => $name,
9999
'uniqueid' => Base64UrlSafe::encode(random_bytes(33)),
100100
'publickey' => $publicKey,

src/Chronicle/Chronicle.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ public static function getTableName(string $name, bool $dontEscape = false)
8181
);
8282
}
8383

84+
/**
85+
* @param string $name
86+
* @param bool $dontEscape
87+
* @return string
88+
* @throws InvalidInstanceException
89+
*/
90+
public static function getTableNameUnquoted(string $name, bool $dontEscape = false)
91+
{
92+
return trim(self::getTableName($name, $dontEscape), '"');
93+
}
94+
8495
/**
8596
* This extends the Blakechain with an arbitrary message, signature, and
8697
* public key.
@@ -92,6 +103,7 @@ public static function getTableName(string $name, bool $dontEscape = false)
92103
*
93104
* @throws BaseException
94105
* @throws \SodiumException
106+
* @psalm-suppress MixedTypeCoercion
95107
*/
96108
public static function extendBlakechain(
97109
string $body,
@@ -150,7 +162,7 @@ public static function extendBlakechain(
150162
self::normalize($db->getDriver(), $fields);
151163

152164
// Insert new row into the database:
153-
$db->insert(self::getTableName('chain', true), $fields);
165+
$db->insert(self::getTableNameUnquoted('chain', true), $fields);
154166
if (!$db->commit()) {
155167
$db->rollBack();
156168
throw new ChainAppendException('Could not commit new hash to database');

src/Chronicle/Handlers/Register.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ public function __invoke(
166166
* @throws \Exception
167167
* @throws InvalidInstanceException
168168
* @throws SecurityViolation
169+
*
170+
* @psalm-suppress MixedTypeCoercion
169171
*/
170172
protected function createClient(array $post): string
171173
{
@@ -185,11 +187,11 @@ protected function createClient(array $post): string
185187

186188
$db->beginTransaction();
187189
$db->insert(
188-
Chronicle::getTableName('clients', true),
190+
Chronicle::getTableNameUnquoted('clients', true),
189191
[
190192
'publicid' => $clientId,
191193
'publickey' => $post['publickey'],
192-
'comment' => $post['comment'] ?? '',
194+
'comment' => (string) ($post['comment'] ?? ''),
193195
'isAdmin' => false,
194196
'created' => $now,
195197
'modified' => $now

src/Chronicle/Process/CrossSign.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
use GuzzleHttp\Exception\GuzzleException;
77
use ParagonIE\Chronicle\Chronicle;
88
use ParagonIE\Chronicle\Error\ConfigurationError;
9-
use ParagonIE\Chronicle\Exception\{
10-
FilesystemException,
11-
TargetNotFound
12-
};
9+
use ParagonIE\Chronicle\Exception\{FilesystemException, InvalidInstanceException, TargetNotFound};
1310
use ParagonIE\ConstantTime\Base64UrlSafe;
1411
use ParagonIE\EasyDB\EasyDB;
1512
use ParagonIE\Sapient\Adapter\Guzzle;
@@ -67,6 +64,7 @@ class CrossSign
6764
* @param SigningPublicKey $publicKey
6865
* @param array $policy
6966
* @param array<string, string> $lastRun
67+
* @throws \Exception
7068
*/
7169
public function __construct(
7270
int $id,
@@ -95,6 +93,7 @@ public function __construct(
9593
* @param int $id
9694
* @return self
9795
*
96+
* @throws InvalidInstanceException
9897
* @throws TargetNotFound
9998
*/
10099
public static function byId(int $id): self
@@ -127,6 +126,7 @@ public static function byId(int $id): self
127126
* @return bool
128127
*
129128
* @throws ConfigurationError
129+
* @throws InvalidInstanceException
130130
*/
131131
public function needsToCrossSign(): bool
132132
{
@@ -179,6 +179,7 @@ public function needsToCrossSign(): bool
179179
* @throws InvalidMessageException
180180
* @throws GuzzleException
181181
* @throws FilesystemException
182+
* @throws InvalidInstanceException
182183
*/
183184
public function performCrossSign(): bool
184185
{
@@ -229,6 +230,7 @@ protected function sendToPeer(array $message): ResponseInterface
229230
*
230231
* @param EasyDB $db
231232
* @return array<string, string>
233+
* @throws InvalidInstanceException
232234
*/
233235
protected function getEndOfChain(EasyDB $db): array
234236
{
@@ -248,12 +250,13 @@ protected function getEndOfChain(EasyDB $db): array
248250
* @param array $response
249251
* @param array $message
250252
* @return bool
253+
* @throws InvalidInstanceException
251254
*/
252255
protected function updateLastRun(EasyDB $db, array $response, array $message): bool
253256
{
254257
$db->beginTransaction();
255258
$db->update(
256-
Chronicle::getTableName('xsign_targets'),
259+
Chronicle::getTableNameUnquoted('xsign_targets'),
257260
[
258261
'lastrun' => \json_encode([
259262
'id' => $message['id'],

src/Chronicle/Process/Replicate.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class Replicate
5353
* @param string $name
5454
* @param string $url
5555
* @param SigningPublicKey $publicKey
56+
* @throws \Exception
5657
*/
5758
public function __construct(
5859
int $id,
@@ -76,6 +77,7 @@ public function __construct(
7677
* @param int $id
7778
* @return self
7879
*
80+
* @throws InvalidInstanceException
7981
* @throws ReplicationSourceNotFound
8082
*/
8183
public static function byId(int $id): self
@@ -104,6 +106,7 @@ public static function byId(int $id): self
104106
* @return void
105107
*
106108
* @throws GuzzleException
109+
* @throws InvalidInstanceException
107110
* @throws InvalidMessageException
108111
* @throws SecurityViolation
109112
* @throws \SodiumException
@@ -196,7 +199,7 @@ protected function appendToChain(array $entry): bool
196199
}
197200

198201
/* Enter the new row to the replication table */
199-
$db->insert(Chronicle::getTableName('replication_chain', true), [
202+
$db->insert(Chronicle::getTableNameUnquoted('replication_chain', true), [
200203
'source' => $this->id,
201204
'data' => $entry['contents'],
202205
'prevhash' => $prevhash,

0 commit comments

Comments
 (0)