forked from olvid-io/olvid-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
1,844 additions
and
425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
obv_engine/engine/src/main/java/io/olvid/engine/datatypes/containers/StringAndBoolean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Olvid for Android | ||
* Copyright © 2019-2024 Olvid SAS | ||
* | ||
* This file is part of Olvid for Android. | ||
* | ||
* Olvid is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* Olvid is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Olvid. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.olvid.engine.datatypes.containers; | ||
|
||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import io.olvid.engine.crypto.Hash; | ||
import io.olvid.engine.crypto.Suite; | ||
import io.olvid.engine.datatypes.UID; | ||
|
||
public class StringAndBoolean { | ||
public final String string; | ||
public final boolean bool; | ||
|
||
public StringAndBoolean(String string, boolean bool) { | ||
this.string = string; | ||
this.bool = bool; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (!(o instanceof StringAndBoolean)) { | ||
return false; | ||
} | ||
StringAndBoolean other = (StringAndBoolean) o; | ||
return string.equals(other.string) && bool == other.bool; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return string.hashCode() * 31 + Boolean.hashCode(bool); | ||
} | ||
|
||
public static UID computeUniqueUid(String string, boolean bool) { | ||
Hash sha256 = Suite.getHash(Hash.SHA256); | ||
byte[] input = new byte[string.getBytes(StandardCharsets.UTF_8).length + 1]; | ||
System.arraycopy(string.getBytes(StandardCharsets.UTF_8), 0, input, 0, input.length - 1); | ||
input[input.length - 1] = bool ? (byte) 0x01 : (byte) 0x00; | ||
return new UID(sha256.digest(input)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ public enum RegisterApiKeyResult { | |
SUCCESS, | ||
INVALID_KEY, | ||
FAILED, | ||
WAIT_FOR_SERVER_SESSION, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.