001/**
002 *
003 * Copyright 2017 Paul Schaub
004 *
005 * This file is part of smack-omemo-signal.
006 *
007 * smack-omemo-signal is free software; you can redistribute it and/or modify
008 * it under the terms of the GNU General Public License as published by
009 * the Free Software Foundation; either version 3 of the License, or
010 * (at your option) any later version.
011 *
012 * This program is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015 * GNU General Public License for more details.
016 *
017 * You should have received a copy of the GNU General Public License
018 * along with this program; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
020 */
021package org.jivesoftware.smackx.omemo.signal;
022
023import org.jivesoftware.smackx.omemo.CachingOmemoStore;
024import org.jivesoftware.smackx.omemo.OmemoStore;
025
026import org.whispersystems.libsignal.IdentityKey;
027import org.whispersystems.libsignal.IdentityKeyPair;
028import org.whispersystems.libsignal.SessionCipher;
029import org.whispersystems.libsignal.SignalProtocolAddress;
030import org.whispersystems.libsignal.ecc.ECPublicKey;
031import org.whispersystems.libsignal.state.PreKeyBundle;
032import org.whispersystems.libsignal.state.PreKeyRecord;
033import org.whispersystems.libsignal.state.SessionRecord;
034import org.whispersystems.libsignal.state.SignedPreKeyRecord;
035
036/**
037 * Implementation of the CachingOmemoStore for smack-omemo-signal.
038 * This Store implementation can either be used as a proxy wrapping a persistent SignalOmemoStore in order to prevent
039 * excessive storage access, or it can be used standalone as an ephemeral store, which doesn't persist its contents.
040 */
041public class SignalCachingOmemoStore extends CachingOmemoStore<IdentityKeyPair, IdentityKey, PreKeyRecord,
042        SignedPreKeyRecord, SessionRecord, SignalProtocolAddress, ECPublicKey, PreKeyBundle, SessionCipher> {
043
044    /**
045     * Create a new SignalCachingOmemoStore as a caching layer around a persisting OmemoStore
046     * (eg. a SignalFileBasedOmemoStore).
047     *
048     * @param wrappedStore other store implementation that gets wrapped
049     */
050    public SignalCachingOmemoStore(OmemoStore<IdentityKeyPair, IdentityKey, PreKeyRecord, SignedPreKeyRecord,
051            SessionRecord, SignalProtocolAddress, ECPublicKey, PreKeyBundle, SessionCipher> wrappedStore) {
052        super(wrappedStore);
053    }
054
055    /**
056     * Create a new SignalCachingOmemoStore as an ephemeral standalone OmemoStore.
057     */
058    public SignalCachingOmemoStore() {
059        super(new SignalOmemoKeyUtil());
060    }
061}