Improve logging in prekey store

This commit is contained in:
AsamK 2022-10-22 17:42:49 +02:00
parent 7805622f07
commit 7ff1500122
2 changed files with 10 additions and 10 deletions

View file

@ -49,7 +49,7 @@ public class PreKeyStore implements org.signal.libsignal.protocol.state.PreKeySt
public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException { public PreKeyRecord loadPreKey(int preKeyId) throws InvalidKeyIdException {
final var preKey = getPreKey(preKeyId); final var preKey = getPreKey(preKeyId);
if (preKey == null) { if (preKey == null) {
throw new InvalidKeyIdException("No such signed pre key record!"); throw new InvalidKeyIdException("No such signed pre key record: " + preKeyId);
} }
return preKey; return preKey;
} }
@ -65,7 +65,7 @@ public class PreKeyStore implements org.signal.libsignal.protocol.state.PreKeySt
try (final var connection = database.getConnection()) { try (final var connection = database.getConnection()) {
try (final var statement = connection.prepareStatement(sql)) { try (final var statement = connection.prepareStatement(sql)) {
statement.setInt(1, accountIdType); statement.setInt(1, accountIdType);
statement.setLong(2, preKeyId); statement.setInt(2, preKeyId);
final var keyPair = record.getKeyPair(); final var keyPair = record.getKeyPair();
statement.setBytes(3, keyPair.getPublicKey().serialize()); statement.setBytes(3, keyPair.getPublicKey().serialize());
statement.setBytes(4, keyPair.getPrivateKey().serialize()); statement.setBytes(4, keyPair.getPrivateKey().serialize());
@ -93,7 +93,7 @@ public class PreKeyStore implements org.signal.libsignal.protocol.state.PreKeySt
try (final var connection = database.getConnection()) { try (final var connection = database.getConnection()) {
try (final var statement = connection.prepareStatement(sql)) { try (final var statement = connection.prepareStatement(sql)) {
statement.setInt(1, accountIdType); statement.setInt(1, accountIdType);
statement.setLong(2, preKeyId); statement.setInt(2, preKeyId);
statement.executeUpdate(); statement.executeUpdate();
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -137,7 +137,7 @@ public class PreKeyStore implements org.signal.libsignal.protocol.state.PreKeySt
try (final var statement = connection.prepareStatement(sql)) { try (final var statement = connection.prepareStatement(sql)) {
for (final var record : preKeys) { for (final var record : preKeys) {
statement.setInt(1, accountIdType); statement.setInt(1, accountIdType);
statement.setLong(2, record.getId()); statement.setInt(2, record.getId());
final var keyPair = record.getKeyPair(); final var keyPair = record.getKeyPair();
statement.setBytes(3, keyPair.getPublicKey().serialize()); statement.setBytes(3, keyPair.getPublicKey().serialize());
statement.setBytes(4, keyPair.getPrivateKey().serialize()); statement.setBytes(4, keyPair.getPrivateKey().serialize());
@ -163,7 +163,7 @@ public class PreKeyStore implements org.signal.libsignal.protocol.state.PreKeySt
try (final var connection = database.getConnection()) { try (final var connection = database.getConnection()) {
try (final var statement = connection.prepareStatement(sql)) { try (final var statement = connection.prepareStatement(sql)) {
statement.setInt(1, accountIdType); statement.setInt(1, accountIdType);
statement.setLong(2, preKeyId); statement.setInt(2, preKeyId);
return Utils.executeQueryForOptional(statement, this::getPreKeyRecordFromResultSet).orElse(null); return Utils.executeQueryForOptional(statement, this::getPreKeyRecordFromResultSet).orElse(null);
} }
} catch (SQLException e) { } catch (SQLException e) {

View file

@ -53,7 +53,7 @@ public class SignedPreKeyStore implements org.signal.libsignal.protocol.state.Si
public SignedPreKeyRecord loadSignedPreKey(int signedPreKeyId) throws InvalidKeyIdException { public SignedPreKeyRecord loadSignedPreKey(int signedPreKeyId) throws InvalidKeyIdException {
final SignedPreKeyRecord signedPreKeyRecord = getSignedPreKey(signedPreKeyId); final SignedPreKeyRecord signedPreKeyRecord = getSignedPreKey(signedPreKeyId);
if (signedPreKeyRecord == null) { if (signedPreKeyRecord == null) {
throw new InvalidKeyIdException("No such signed pre key record!"); throw new InvalidKeyIdException("No such signed pre key record: " + signedPreKeyId);
} }
return signedPreKeyRecord; return signedPreKeyRecord;
} }
@ -90,7 +90,7 @@ public class SignedPreKeyStore implements org.signal.libsignal.protocol.state.Si
try (final var connection = database.getConnection()) { try (final var connection = database.getConnection()) {
try (final var statement = connection.prepareStatement(sql)) { try (final var statement = connection.prepareStatement(sql)) {
statement.setInt(1, accountIdType); statement.setInt(1, accountIdType);
statement.setLong(2, signedPreKeyId); statement.setInt(2, signedPreKeyId);
final var keyPair = record.getKeyPair(); final var keyPair = record.getKeyPair();
statement.setBytes(3, keyPair.getPublicKey().serialize()); statement.setBytes(3, keyPair.getPublicKey().serialize());
statement.setBytes(4, keyPair.getPrivateKey().serialize()); statement.setBytes(4, keyPair.getPrivateKey().serialize());
@ -119,7 +119,7 @@ public class SignedPreKeyStore implements org.signal.libsignal.protocol.state.Si
try (final var connection = database.getConnection()) { try (final var connection = database.getConnection()) {
try (final var statement = connection.prepareStatement(sql)) { try (final var statement = connection.prepareStatement(sql)) {
statement.setInt(1, accountIdType); statement.setInt(1, accountIdType);
statement.setLong(2, signedPreKeyId); statement.setInt(2, signedPreKeyId);
statement.executeUpdate(); statement.executeUpdate();
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -163,7 +163,7 @@ public class SignedPreKeyStore implements org.signal.libsignal.protocol.state.Si
try (final var statement = connection.prepareStatement(sql)) { try (final var statement = connection.prepareStatement(sql)) {
for (final var record : signedPreKeys) { for (final var record : signedPreKeys) {
statement.setInt(1, accountIdType); statement.setInt(1, accountIdType);
statement.setLong(2, record.getId()); statement.setInt(2, record.getId());
final var keyPair = record.getKeyPair(); final var keyPair = record.getKeyPair();
statement.setBytes(3, keyPair.getPublicKey().serialize()); statement.setBytes(3, keyPair.getPublicKey().serialize());
statement.setBytes(4, keyPair.getPrivateKey().serialize()); statement.setBytes(4, keyPair.getPrivateKey().serialize());
@ -190,7 +190,7 @@ public class SignedPreKeyStore implements org.signal.libsignal.protocol.state.Si
try (final var connection = database.getConnection()) { try (final var connection = database.getConnection()) {
try (final var statement = connection.prepareStatement(sql)) { try (final var statement = connection.prepareStatement(sql)) {
statement.setInt(1, accountIdType); statement.setInt(1, accountIdType);
statement.setLong(2, signedPreKeyId); statement.setInt(2, signedPreKeyId);
return Utils.executeQueryForOptional(statement, this::getSignedPreKeyRecordFromResultSet).orElse(null); return Utils.executeQueryForOptional(statement, this::getSignedPreKeyRecordFromResultSet).orElse(null);
} }
} catch (SQLException e) { } catch (SQLException e) {