mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-09 10:19:41 +02:00
Use StandardCharsets.(UTF_8|US_ASCII)
This also gets rid of a ton of UnsupportedEncodingException s.
This commit is contained in:
parent
2a4d110b22
commit
d2f5efcb20
33 changed files with 125 additions and 227 deletions
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.omemo;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
@ -25,8 +25,6 @@ import java.util.logging.Logger;
|
|||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
import org.jivesoftware.smackx.omemo.element.OmemoElement;
|
||||
import org.jivesoftware.smackx.omemo.element.OmemoKeyElement;
|
||||
import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException;
|
||||
|
@ -169,10 +167,9 @@ public abstract class OmemoRatchet<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
|||
byte[] encryptedBody = payloadAndAuthTag(element, cipherAndAuthTag.getAuthTag());
|
||||
|
||||
try {
|
||||
String plaintext = new String(cipherAndAuthTag.getCipher().doFinal(encryptedBody), StringUtils.UTF8);
|
||||
String plaintext = new String(cipherAndAuthTag.getCipher().doFinal(encryptedBody), StandardCharsets.UTF_8);
|
||||
return plaintext;
|
||||
|
||||
} catch (UnsupportedEncodingException | IllegalBlockSizeException | BadPaddingException e) {
|
||||
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
||||
throw new CryptoFailedException("decryptMessageElement could not decipher message body: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.jivesoftware.smackx.omemo;
|
|||
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.KEYLENGTH;
|
||||
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.KEYTYPE;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
@ -309,7 +308,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
|||
try {
|
||||
builder = new OmemoMessageBuilder<>(userDevice, gullibleTrustCallback, getOmemoRatchet(manager),
|
||||
messageKey, iv, null);
|
||||
} catch (InvalidKeyException | InvalidAlgorithmParameterException | NoSuchPaddingException | BadPaddingException | UnsupportedEncodingException | IllegalBlockSizeException e) {
|
||||
} catch (InvalidKeyException | InvalidAlgorithmParameterException | NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException e) {
|
||||
throw new CryptoFailedException(e);
|
||||
}
|
||||
|
||||
|
@ -371,7 +370,7 @@ public abstract class OmemoService<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey,
|
|||
try {
|
||||
builder = new OmemoMessageBuilder<>(
|
||||
userDevice, manager.getTrustCallback(), getOmemoRatchet(managerGuard.get()), messageKey, iv, message);
|
||||
} catch (UnsupportedEncodingException | BadPaddingException | IllegalBlockSizeException |
|
||||
} catch (BadPaddingException | IllegalBlockSizeException |
|
||||
NoSuchPaddingException | InvalidAlgorithmParameterException | InvalidKeyException | NoSuchAlgorithmException e) {
|
||||
throw new CryptoFailedException(e);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.KEYLENGTH
|
|||
import static org.jivesoftware.smackx.omemo.util.OmemoConstants.Crypto.KEYTYPE;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
@ -37,8 +38,6 @@ import javax.crypto.SecretKey;
|
|||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
import org.jivesoftware.smackx.omemo.OmemoRatchet;
|
||||
import org.jivesoftware.smackx.omemo.OmemoService;
|
||||
import org.jivesoftware.smackx.omemo.element.OmemoElement;
|
||||
|
@ -96,7 +95,6 @@ public class OmemoMessageBuilder<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
|
|||
* @throws InvalidKeyException
|
||||
* @throws NoSuchAlgorithmException
|
||||
* @throws IllegalBlockSizeException
|
||||
* @throws UnsupportedEncodingException
|
||||
* @throws InvalidAlgorithmParameterException
|
||||
*/
|
||||
public OmemoMessageBuilder(OmemoDevice userDevice,
|
||||
|
@ -107,7 +105,7 @@ public class OmemoMessageBuilder<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
|
|||
String message)
|
||||
throws NoSuchPaddingException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException,
|
||||
IllegalBlockSizeException,
|
||||
UnsupportedEncodingException, InvalidAlgorithmParameterException {
|
||||
InvalidAlgorithmParameterException {
|
||||
this.userDevice = userDevice;
|
||||
this.trustCallback = callback;
|
||||
this.ratchet = ratchet;
|
||||
|
@ -152,11 +150,12 @@ public class OmemoMessageBuilder<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
|
|||
* @throws NoSuchProviderException
|
||||
* @throws InvalidAlgorithmParameterException
|
||||
* @throws InvalidKeyException
|
||||
* @throws UnsupportedEncodingException
|
||||
* @throws BadPaddingException
|
||||
* @throws IllegalBlockSizeException
|
||||
*/
|
||||
private void setMessage(String message) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, UnsupportedEncodingException, BadPaddingException, IllegalBlockSizeException {
|
||||
private void setMessage(String message)
|
||||
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
|
||||
InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
|
||||
if (message == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -170,7 +169,7 @@ public class OmemoMessageBuilder<T_IdKeyPair, T_IdKey, T_PreKey, T_SigPreKey, T_
|
|||
byte[] body;
|
||||
byte[] ciphertext;
|
||||
|
||||
body = message.getBytes(StringUtils.UTF8);
|
||||
body = message.getBytes(StandardCharsets.UTF_8);
|
||||
ciphertext = cipher.doFinal(body);
|
||||
|
||||
byte[] clearKeyWithAuthTag = new byte[messageKey.length + 16];
|
||||
|
|
|
@ -19,12 +19,12 @@ package org.jivesoftware.smackx.omemo;
|
|||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
|
@ -41,12 +41,12 @@ public class OmemoBundleVAxolotlElementTest extends SmackTestSuite {
|
|||
@Test
|
||||
public void serializationTest() throws Exception {
|
||||
int signedPreKeyId = 420;
|
||||
String signedPreKeyB64 = Base64.encodeToString("SignedPreKey".getBytes(StringUtils.UTF8));
|
||||
String signedPreKeySigB64 = Base64.encodeToString("SignedPreKeySignature".getBytes(StringUtils.UTF8));
|
||||
String identityKeyB64 = Base64.encodeToString("IdentityKey".getBytes(StringUtils.UTF8));
|
||||
String signedPreKeyB64 = Base64.encodeToString("SignedPreKey".getBytes(StandardCharsets.UTF_8));
|
||||
String signedPreKeySigB64 = Base64.encodeToString("SignedPreKeySignature".getBytes(StandardCharsets.UTF_8));
|
||||
String identityKeyB64 = Base64.encodeToString("IdentityKey".getBytes(StandardCharsets.UTF_8));
|
||||
int preKeyId1 = 220, preKeyId2 = 284;
|
||||
String preKey1B64 = Base64.encodeToString("FirstPreKey".getBytes(StringUtils.UTF8)),
|
||||
preKey2B64 = Base64.encodeToString("SecondPreKey".getBytes(StringUtils.UTF8));
|
||||
String preKey1B64 = Base64.encodeToString("FirstPreKey".getBytes(StandardCharsets.UTF_8)),
|
||||
preKey2B64 = Base64.encodeToString("SecondPreKey".getBytes(StandardCharsets.UTF_8));
|
||||
HashMap<Integer, String> preKeysB64 = new HashMap<>();
|
||||
preKeysB64.put(preKeyId1, preKey1B64);
|
||||
preKeysB64.put(preKeyId2, preKey2B64);
|
||||
|
@ -80,11 +80,11 @@ public class OmemoBundleVAxolotlElementTest extends SmackTestSuite {
|
|||
String actual = bundle.toXML().toString();
|
||||
assertEquals("Bundles XML must match.", expected, actual);
|
||||
|
||||
byte[] signedPreKey = "SignedPreKey".getBytes(StringUtils.UTF8);
|
||||
byte[] signedPreKeySig = "SignedPreKeySignature".getBytes(StringUtils.UTF8);
|
||||
byte[] identityKey = "IdentityKey".getBytes(StringUtils.UTF8);
|
||||
byte[] firstPreKey = "FirstPreKey".getBytes(StringUtils.UTF8);
|
||||
byte[] secondPreKey = "SecondPreKey".getBytes(StringUtils.UTF8);
|
||||
byte[] signedPreKey = "SignedPreKey".getBytes(StandardCharsets.UTF_8);
|
||||
byte[] signedPreKeySig = "SignedPreKeySignature".getBytes(StandardCharsets.UTF_8);
|
||||
byte[] identityKey = "IdentityKey".getBytes(StandardCharsets.UTF_8);
|
||||
byte[] firstPreKey = "FirstPreKey".getBytes(StandardCharsets.UTF_8);
|
||||
byte[] secondPreKey = "SecondPreKey".getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
OmemoBundleElement_VAxolotl parsed = new OmemoBundleVAxolotlProvider().parse(TestUtils.getParser(actual));
|
||||
|
||||
|
|
|
@ -18,11 +18,11 @@ package org.jivesoftware.smackx.omemo;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base64;
|
||||
|
||||
import org.jivesoftware.smackx.omemo.element.OmemoElement_VAxolotl;
|
||||
|
@ -40,11 +40,11 @@ public class OmemoVAxolotlElementTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void serializationTest() throws Exception {
|
||||
byte[] payload = "This is payload.".getBytes(StringUtils.UTF8);
|
||||
byte[] payload = "This is payload.".getBytes(StandardCharsets.UTF_8);
|
||||
int keyId1 = 8;
|
||||
int keyId2 = 33333;
|
||||
byte[] keyData1 = "KEYDATA".getBytes(StringUtils.UTF8);
|
||||
byte[] keyData2 = "DATAKEY".getBytes(StringUtils.UTF8);
|
||||
byte[] keyData1 = "KEYDATA".getBytes(StandardCharsets.UTF_8);
|
||||
byte[] keyData2 = "DATAKEY".getBytes(StandardCharsets.UTF_8);
|
||||
int sid = 12131415;
|
||||
byte[] iv = OmemoMessageBuilder.generateIv();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue