1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-11 18:19:38 +02:00

Cleanup code

This commit is contained in:
vanitasvitae 2017-08-16 15:36:49 +02:00
parent e53165a96c
commit e1655aa344
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
30 changed files with 92 additions and 109 deletions

View file

@ -35,9 +35,9 @@ public abstract class AesGcmNoPadding {
private final int length;
protected final Cipher cipher;
protected final byte[] key, iv, keyAndIv;
private final byte[] key, iv, keyAndIv;
protected AesGcmNoPadding(int bits, int MODE) throws NoSuchAlgorithmException, NoSuchProviderException,
AesGcmNoPadding(int bits, int MODE) throws NoSuchAlgorithmException, NoSuchProviderException,
NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException {
this.length = bits;
int bytes = bits / 8;
@ -136,7 +136,7 @@ public abstract class AesGcmNoPadding {
public abstract String getNamespace();
public static byte[] copyOfRange(byte[] source, int start, int end) {
static byte[] copyOfRange(byte[] source, int start, int end) {
byte[] copy = new byte[end - start];
System.arraycopy(source, start, copy, 0, end - start);
return copy;

View file

@ -52,19 +52,19 @@ public class JetSecurity extends JingleSecurity<JetSecurityElement> {
private final String methodNamespace;
private AesGcmNoPadding aesKey;
private ExtensionElement child;
private String cipherName;
private String name;
private final ExtensionElement child;
private final String cipherName;
private final String contentName;
public JetSecurity(JetSecurityElement element) {
super();
this.child = element.getChild();
this.methodNamespace = element.getMethodNamespace();
this.name = element.getName();
this.contentName = element.getContentName();
this.cipherName = element.getCipherName();
}
public JetSecurity(JingleEncryptionMethod method, FullJid recipient, String name, String cipherName)
public JetSecurity(JingleEncryptionMethod method, FullJid recipient, String contentName, String cipherName)
throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException,
InvalidAlgorithmParameterException, InvalidKeyException, InterruptedException,
JingleEncryptionMethod.JingleEncryptionException, SmackException.NotConnectedException,
@ -73,11 +73,11 @@ public class JetSecurity extends JingleSecurity<JetSecurityElement> {
this.methodNamespace = method.getNamespace();
this.aesKey = AesGcmNoPadding.createEncryptionKey(cipherName);
this.child = method.encryptJingleTransfer(recipient, aesKey.getKeyAndIv());
this.name = name;
this.contentName = contentName;
this.cipherName = cipherName;
}
public void decryptEncryptionKey(JingleEncryptionMethod method, FullJid sender)
private void decryptEncryptionKey(JingleEncryptionMethod method, FullJid sender)
throws InterruptedException, JingleEncryptionMethod.JingleEncryptionException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException, NoSuchAlgorithmException,
InvalidAlgorithmParameterException, NoSuchProviderException, InvalidKeyException, NoSuchPaddingException {
@ -87,7 +87,7 @@ public class JetSecurity extends JingleSecurity<JetSecurityElement> {
@Override
public JetSecurityElement getElement() {
return new JetSecurityElement(name, cipherName, child);
return new JetSecurityElement(contentName, cipherName, child);
}
@Override

View file

@ -71,7 +71,7 @@ public class JetSecurityElement extends JingleContentSecurityElement {
return child;
}
public String getName() {
public String getContentName() {
return name;
}

View file

@ -60,6 +60,7 @@ import org.jxmpp.jid.FullJid;
* Created by vanitas on 22.07.17.
*/
public final class JingleFileTransferManager extends Manager implements JingleDescriptionManager {
private static final Logger LOGGER = Logger.getLogger(JingleFileTransferManager.class.getName());
private static final WeakHashMap<XMPPConnection, JingleFileTransferManager> INSTANCES = new WeakHashMap<>();

View file

@ -21,7 +21,7 @@ package org.jivesoftware.smackx.jingle_filetransfer.component;
*/
public abstract class AbstractJingleFileOffer<D extends JingleFileTransferFile> extends JingleFileTransfer {
public AbstractJingleFileOffer(D fileTransferFile) {
AbstractJingleFileOffer(D fileTransferFile) {
super(fileTransferFile);
}

View file

@ -21,7 +21,7 @@ package org.jivesoftware.smackx.jingle_filetransfer.component;
*/
public abstract class AbstractJingleFileRequest<D extends JingleFileTransferFile> extends JingleFileTransfer {
public AbstractJingleFileRequest(D fileTransferFile) {
AbstractJingleFileRequest(D fileTransferFile) {
super(fileTransferFile);
}

View file

@ -39,9 +39,9 @@ public abstract class JingleFileTransfer extends JingleDescription<JingleFileTra
protected State state;
protected JingleFileTransferFile file;
protected final List<ProgressListener> progressListeners = Collections.synchronizedList(new ArrayList<ProgressListener>());
private final List<ProgressListener> progressListeners = Collections.synchronizedList(new ArrayList<ProgressListener>());
public JingleFileTransfer(JingleFileTransferFile file) {
JingleFileTransfer(JingleFileTransferFile file) {
this.file = file;
}
@ -56,6 +56,11 @@ public abstract class JingleFileTransfer extends JingleDescription<JingleFileTra
progressListeners.remove(listener);
}
@Override
public void cancel() {
//TODO
}
public void notifyProgressListeners(float progress) {
for (ProgressListener p : progressListeners) {
p.progress(progress);

View file

@ -58,7 +58,7 @@ public abstract class JingleFileTransferFile {
public static class LocalFile extends JingleFileTransferFile {
private File file;
private final File file;
private String name;
private String description;
private String mediaType;
@ -137,7 +137,7 @@ public abstract class JingleFileTransferFile {
public static class RemoteFile extends JingleFileTransferFile {
private JingleFileTransferChildElement file;
private final JingleFileTransferChildElement file;
public RemoteFile(JingleFileTransferChildElement file) {
super();

View file

@ -28,6 +28,8 @@ import org.jivesoftware.smack.XMPPException;
* User interface for an incoming Jingle file offer.
*/
public interface IncomingFileOfferController extends JingleFileTransferController {
void accept(XMPPConnection connection, File target) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, IOException;
void accept(XMPPConnection connection, OutputStream outputStream) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, IOException;
}

View file

@ -20,5 +20,5 @@ package org.jivesoftware.smackx.jingle_filetransfer.controller;
* Created by vanitas on 27.07.17.
*/
public interface IncomingFileRequestController extends JingleFileTransferController {
//TODO: Declare methods.
}

View file

@ -30,4 +30,6 @@ public interface JingleFileTransferController extends JingleDescriptionControlle
void removeProgressListener(ProgressListener listener);
JingleFileTransferFile getFile();
void cancel();
}

View file

@ -20,5 +20,5 @@ package org.jivesoftware.smackx.jingle_filetransfer.controller;
* Created by vanitas on 27.07.17.
*/
public interface OutgoingFileOfferController extends JingleFileTransferController {
//TODO: Declare methods.
}

View file

@ -20,4 +20,5 @@ package org.jivesoftware.smackx.jingle_filetransfer.controller;
* Created by vanitas on 27.07.17.
*/
public interface OutgoingFileRequestController extends JingleFileTransferController {
//TODO: Declare methods.
}

View file

@ -26,6 +26,7 @@ import org.jivesoftware.smackx.jingle_filetransfer.component.JingleFileTransfer;
* Checksum element.
*/
public class ChecksumElement implements ExtensionElement {
public static final String ELEMENT = "checksum";
public static final String ATTR_CREATOR = "creator";
public static final String ATTR_NAME = "name";

View file

@ -27,6 +27,7 @@ import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildEleme
* Content of type File.
*/
public class JingleFileTransferChildElement extends JingleContentDescriptionChildElement {
public static final String ELEMENT = "file";
public static final String ELEM_DATE = "date";
public static final String ELEM_DESC = "desc";
@ -139,8 +140,8 @@ public class JingleFileTransferChildElement extends JingleContentDescriptionChil
* This is a MIME type from this list:
* https://www.iana.org/assignments/media-types/media-types.xhtml
* Default should be application/octet-stream.
* @param mediaType
* @return
* @param mediaType new media type.
* @return builder.
*/
public Builder setMediaType(String mediaType) {
this.mediaType = mediaType;

View file

@ -35,6 +35,7 @@ import org.xmlpull.v1.XmlPullParser;
* Provider for the Checksum element.
*/
public class ChecksumProvider extends ExtensionElementProvider<ChecksumElement> {
@Override
public ChecksumElement parse(XmlPullParser parser, int initialDepth) throws Exception {
JingleContentElement.Creator creator = null;

View file

@ -45,7 +45,7 @@ public class JetElementTest extends SmackTestSuite {
assertEquals(SecurityStub.NAMESPACE, security.getMethodNamespace());
assertEquals(Aes128GcmNoPadding.NAMESPACE, element.getCipherName());
assertEquals(SecurityStub.NAMESPACE, element.getMethodNamespace());
assertEquals("content1", element.getName());
assertEquals("content1", element.getContentName());
String xml = "<security xmlns='" + JetSecurity.NAMESPACE + "' " +
"name='content1' " +