001/**
002 *
003 * Copyright 2017 Paul Schaub
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.omemo.internal;
018
019import static org.jivesoftware.smackx.omemo.element.OmemoElement.TYPE_OMEMO_PREKEY_MESSAGE;
020
021/**
022 * Bundles a decrypted ciphertext together with information about the message type.
023 *
024 * @author Paul Schaub
025 */
026public class CiphertextTuple {
027    private final byte[] ciphertext;
028    private final int messageType;
029
030    /**
031     * Create a new CiphertextTuple.
032     *
033     * @param ciphertext ciphertext
034     * @param type type
035     */
036    public CiphertextTuple(byte[] ciphertext, int type) {
037        this.ciphertext = ciphertext;
038        this.messageType = type;
039    }
040
041    /**
042     * Return the ciphertext.
043     *
044     * @return ciphertext
045     */
046    public byte[] getCiphertext() {
047        return ciphertext;
048    }
049
050    /**
051     * Return the messageType.
052     *
053     * @return messageType
054     */
055    public int getMessageType() {
056        return this.messageType;
057    }
058
059    /**
060     * Returns true if this is a preKeyMessage.
061     *
062     * @return preKeyMessage?
063     */
064    public boolean isPreKeyMessage() {
065        return getMessageType() == TYPE_OMEMO_PREKEY_MESSAGE;
066    }
067}