2017-08-25 12:00:52 -07:00
|
|
|
package org.thoughtcrime.securesms.crypto;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.util.Base64;
|
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
public class ProfileKeyUtil {
|
|
|
|
|
2017-09-12 22:49:30 -07:00
|
|
|
public static synchronized boolean hasProfileKey(@NonNull Context context) {
|
|
|
|
return TextSecurePreferences.getProfileKey(context) != null;
|
|
|
|
}
|
|
|
|
|
2017-08-25 12:00:52 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 16:45:22 -07:00
|
|
|
public static synchronized @NonNull byte[] rotateProfileKey(@NonNull Context context) {
|
|
|
|
TextSecurePreferences.setProfileKey(context, null);
|
|
|
|
return getProfileKey(context);
|
|
|
|
}
|
2017-08-25 12:00:52 -07:00
|
|
|
}
|