001/** 002 * 003 * Copyright 2018 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.exceptions; 018 019import java.util.Date; 020 021import org.jivesoftware.smackx.omemo.internal.OmemoDevice; 022 023public class StaleDeviceException extends Exception { 024 private static final long serialVersionUID = 1L; 025 026 private final OmemoDevice device; 027 private final Date lastMessageDate; 028 private final Date lastDeviceIdPublication; 029 030 /** 031 * This exception gets thrown if a message cannot be encrypted for a device due to the device being inactive for too long (stale). 032 * 033 * @param device OmemoDevice. 034 * @param lastMessageDate 035 * @param lastDeviceIdPublicationDate 036 */ 037 public StaleDeviceException(OmemoDevice device, Date lastMessageDate, Date lastDeviceIdPublicationDate) { 038 this.device = device; 039 this.lastMessageDate = lastMessageDate; 040 this.lastDeviceIdPublication = lastDeviceIdPublicationDate; 041 } 042 043 /** 044 * Return the date on which the last OMEMO message sent from the device was received. 045 * @return last messages date 046 */ 047 public Date getLastMessageDate() { 048 return lastMessageDate; 049 } 050 051 /** 052 * Return the date of the last time the deviceId was republished after being inactive/non-existent before. 053 * @return date of last deviceId (re)publication. 054 */ 055 public Date getLastDeviceIdPublicationDate() { 056 return lastDeviceIdPublication; 057 } 058 059 /** 060 * Return the stale OMEMO device. 061 * @return stale device 062 */ 063 public OmemoDevice getDevice() { 064 return device; 065 } 066}