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;
018
019public class OmemoFingerprint implements CharSequence {
020
021    private final String fingerprintString;
022
023    public OmemoFingerprint(String fingerprintString) {
024        this.fingerprintString = fingerprintString;
025    }
026
027    @Override
028    public int length() {
029        return fingerprintString.length();
030    }
031
032    @Override
033    public char charAt(int index) {
034        return fingerprintString.charAt(index);
035    }
036
037    @Override
038    public CharSequence subSequence(int start, int end) {
039        return fingerprintString.subSequence(start, end);
040    }
041
042    public CharSequence subSequence(int start) {
043        return fingerprintString.subSequence(start, fingerprintString.length() - 1);
044    }
045
046    @Override
047    public String toString() {
048        return fingerprintString;
049    }
050
051    @Override
052    public boolean equals(Object other) {
053        if (!(other instanceof OmemoFingerprint)) {
054            return false;
055        }
056        OmemoFingerprint otherFingerprint = (OmemoFingerprint) other;
057        return this.toString().trim().equals(otherFingerprint.toString().trim());
058    }
059
060    @Override
061    public int hashCode() {
062        return toString().hashCode();
063    }
064}