-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
1 parent
b92c389
commit f10d1ea
Showing
11 changed files
with
87 additions
and
57 deletions.
There are no files selected for viewing
39 changes: 13 additions & 26 deletions
39
app/src/main/java/org/thoughtcrime/securesms/crypto/ProfileKeyUtil.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 |
---|---|---|
@@ -1,38 +1,25 @@ | ||
package org.thoughtcrime.securesms.crypto; | ||
|
||
|
||
import android.content.Context; | ||
import androidx.annotation.NonNull; | ||
|
||
import org.thoughtcrime.securesms.util.Base64; | ||
import org.thoughtcrime.securesms.util.TextSecurePreferences; | ||
import org.thoughtcrime.securesms.util.Util; | ||
import androidx.annotation.NonNull; | ||
|
||
import java.io.IOException; | ||
import org.thoughtcrime.securesms.recipients.Recipient; | ||
|
||
public class ProfileKeyUtil { | ||
public final class ProfileKeyUtil { | ||
|
||
public static synchronized boolean hasProfileKey(@NonNull Context context) { | ||
return TextSecurePreferences.getProfileKey(context) != null; | ||
private ProfileKeyUtil() { | ||
} | ||
|
||
public static synchronized @NonNull byte[] getProfileKey(@NonNull Context context) { | ||
try { | ||
String encodedProfileKey = TextSecurePreferences.getProfileKey(context); | ||
|
||
if (encodedProfileKey == null) { | ||
encodedProfileKey = Util.getSecret(32); | ||
TextSecurePreferences.setProfileKey(context, encodedProfileKey); | ||
} | ||
|
||
return Base64.decode(encodedProfileKey); | ||
} catch (IOException e) { | ||
throw new AssertionError(e); | ||
/** | ||
* @deprecated Will inline later as part of Versioned profiles. | ||
*/ | ||
@Deprecated | ||
public static @NonNull byte[] getProfileKey(@NonNull Context context) { | ||
byte[] profileKey = Recipient.self().getProfileKey(); | ||
if (profileKey == null) { | ||
throw new AssertionError(); | ||
} | ||
} | ||
|
||
public static synchronized @NonNull byte[] rotateProfileKey(@NonNull Context context) { | ||
TextSecurePreferences.setProfileKey(context, null); | ||
return getProfileKey(context); | ||
return profileKey; | ||
} | ||
} |
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
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