From b3c00d7163924b7ed26f6e40d90ea08b90945df1 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 4 Dec 2019 17:35:06 +0100 Subject: [PATCH] use Base64.NO_WRAP instead of trim() --- .../entities/ServiceDiscoveryResult.java | 2 +- .../generator/AbstractGenerator.java | 4 ++-- .../conversations/generator/IqGenerator.java | 16 ++++++---------- .../siacs/conversations/utils/CursorUtils.java | 2 +- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java index 3e2761101..c4babe81c 100644 --- a/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java +++ b/src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java @@ -158,7 +158,7 @@ public class ServiceDiscoveryResult { } public String getVer() { - return new String(Base64.encode(this.ver, Base64.DEFAULT)).trim(); + return Base64.encodeToString(this.ver, Base64.NO_WRAP); } public List getIdentities() { diff --git a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java index df15f39e2..a24a4ba0d 100644 --- a/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java @@ -99,8 +99,8 @@ public abstract class AbstractGenerator { for (String feature : getFeatures(account)) { s.append(feature).append('<'); } - byte[] sha1 = md.digest(s.toString().getBytes()); - return new String(Base64.encode(sha1, Base64.DEFAULT)).trim(); + final byte[] sha1 = md.digest(s.toString().getBytes()); + return Base64.encodeToString(sha1, Base64.NO_WRAP); } public static String getTimestamp(long time) { diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java index 1f9de7e6c..62670c408 100644 --- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java @@ -160,10 +160,6 @@ public class IqGenerator extends AbstractGenerator { return publish("urn:xmpp:avatar:data", item, options); } - public IqPacket publishElement(final String namespace, final Element element, final Bundle options) { - return publishElement(namespace, element, "curent", options); - } - public IqPacket publishElement(final String namespace, final Element element, String id, final Bundle options) { final Element item = new Element("item"); item.setAttribute("id", id); @@ -263,17 +259,17 @@ public class IqGenerator extends AbstractGenerator { final Element signedPreKeyPublic = bundle.addChild("signedPreKeyPublic"); signedPreKeyPublic.setAttribute("signedPreKeyId", signedPreKeyRecord.getId()); ECPublicKey publicKey = signedPreKeyRecord.getKeyPair().getPublicKey(); - signedPreKeyPublic.setContent(Base64.encodeToString(publicKey.serialize(), Base64.DEFAULT)); + signedPreKeyPublic.setContent(Base64.encodeToString(publicKey.serialize(), Base64.NO_WRAP)); final Element signedPreKeySignature = bundle.addChild("signedPreKeySignature"); - signedPreKeySignature.setContent(Base64.encodeToString(signedPreKeyRecord.getSignature(), Base64.DEFAULT)); + signedPreKeySignature.setContent(Base64.encodeToString(signedPreKeyRecord.getSignature(), Base64.NO_WRAP)); final Element identityKeyElement = bundle.addChild("identityKey"); - identityKeyElement.setContent(Base64.encodeToString(identityKey.serialize(), Base64.DEFAULT)); + identityKeyElement.setContent(Base64.encodeToString(identityKey.serialize(), Base64.NO_WRAP)); final Element prekeys = bundle.addChild("prekeys", AxolotlService.PEP_PREFIX); for (PreKeyRecord preKeyRecord : preKeyRecords) { final Element prekey = prekeys.addChild("preKeyPublic"); prekey.setAttribute("preKeyId", preKeyRecord.getId()); - prekey.setContent(Base64.encodeToString(preKeyRecord.getKeyPair().getPublicKey().serialize(), Base64.DEFAULT)); + prekey.setContent(Base64.encodeToString(preKeyRecord.getKeyPair().getPublicKey().serialize(), Base64.NO_WRAP)); } return publish(AxolotlService.PEP_BUNDLES + ":" + deviceId, item, publishOptions); @@ -287,13 +283,13 @@ public class IqGenerator extends AbstractGenerator { for (int i = 0; i < certificates.length; ++i) { try { Element certificate = chain.addChild("certificate"); - certificate.setContent(Base64.encodeToString(certificates[i].getEncoded(), Base64.DEFAULT)); + certificate.setContent(Base64.encodeToString(certificates[i].getEncoded(), Base64.NO_WRAP)); certificate.setAttribute("index", i); } catch (CertificateEncodingException e) { Log.d(Config.LOGTAG, "could not encode certificate"); } } - verification.addChild("signature").setContent(Base64.encodeToString(signature, Base64.DEFAULT)); + verification.addChild("signature").setContent(Base64.encodeToString(signature, Base64.NO_WRAP)); return publish(AxolotlService.PEP_VERIFICATION + ":" + deviceId, item); } diff --git a/src/main/java/eu/siacs/conversations/utils/CursorUtils.java b/src/main/java/eu/siacs/conversations/utils/CursorUtils.java index d54bd7c02..832bed7dc 100644 --- a/src/main/java/eu/siacs/conversations/utils/CursorUtils.java +++ b/src/main/java/eu/siacs/conversations/utils/CursorUtils.java @@ -11,7 +11,7 @@ public class CursorUtils { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) { if (cursor instanceof AbstractWindowedCursor) { final AbstractWindowedCursor windowedCursor = (AbstractWindowedCursor) cursor; - windowedCursor.setWindow(new CursorWindow("8k", 8 * 1024 * 1024)); + windowedCursor.setWindow(new CursorWindow("8M", 8 * 1024 * 1024)); } if (cursor instanceof SQLiteCursor) { ((SQLiteCursor) cursor).setFillWindowForwardOnly(true);