xep-0285: Add verification classes
This commit is contained in:
parent
be59c09b15
commit
cc198371b0
|
@ -0,0 +1,29 @@
|
|||
package org.jivesoftware.smackx.signed.xep0285.verification;
|
||||
|
||||
import org.jivesoftware.smackx.signed.xep0285.element.PlainElement;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* So boring...
|
||||
*/
|
||||
public class StrictlyMonotoneTimestampValidator implements TimestampValidator {
|
||||
|
||||
private Date lastTimestamp;
|
||||
|
||||
public StrictlyMonotoneTimestampValidator(Date lastTimestamp) {
|
||||
this.lastTimestamp = lastTimestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(PlainElement plainElement) {
|
||||
if (plainElement.getTimestamp() == null) {
|
||||
return false;
|
||||
}
|
||||
return lastTimestamp == null || plainElement.getTimestamp().after(lastTimestamp);
|
||||
}
|
||||
|
||||
public void set(PlainElement plainElement) {
|
||||
this.lastTimestamp = plainElement.getTimestamp();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package org.jivesoftware.smackx.signed.xep0285.verification;
|
||||
|
||||
import org.jivesoftware.smackx.signed.xep0285.element.PlainElement;
|
||||
|
||||
public interface TimestampValidator {
|
||||
|
||||
boolean isValid(PlainElement plainElement);
|
||||
|
||||
void set(PlainElement plainElement);
|
||||
|
||||
default boolean compareAndSet(PlainElement plainElement) {
|
||||
if (isValid(plainElement)) {
|
||||
set(plainElement);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue