mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 22:29:53 +01:00
Use base32 for contact links.
This commit is contained in:
@@ -153,4 +153,15 @@ public class StringUtils {
|
|||||||
return new String(c);
|
return new String(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getRandomBase32String(int length) {
|
||||||
|
char[] c = new char[length];
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
int character = random.nextInt(32);
|
||||||
|
if (character < 26) c[i] = (char) ('A' + character);
|
||||||
|
else c[i] = (char) ('2' + (character - 26));
|
||||||
|
}
|
||||||
|
return new String(c);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,8 @@ public class ContactLinkInputActivity extends BriarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBriarLink(CharSequence s) {
|
private boolean isBriarLink(CharSequence s) {
|
||||||
return s.length() == 72 && s.toString().startsWith("briar://");
|
String regex = "^briar://[A-Z2-7]{64}$";
|
||||||
|
return s.toString().trim().matches(regex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAddButtonState() {
|
private void updateAddButtonState() {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import javax.annotation.Nullable;
|
|||||||
import static android.content.Intent.ACTION_SEND;
|
import static android.content.Intent.ACTION_SEND;
|
||||||
import static android.content.Intent.EXTRA_TEXT;
|
import static android.content.Intent.EXTRA_TEXT;
|
||||||
import static android.widget.Toast.LENGTH_SHORT;
|
import static android.widget.Toast.LENGTH_SHORT;
|
||||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
import static org.briarproject.bramble.util.StringUtils.getRandomBase32String;
|
||||||
|
|
||||||
public class ContactLinkOutputActivity extends BriarActivity {
|
public class ContactLinkOutputActivity extends BriarActivity {
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ public class ContactLinkOutputActivity extends BriarActivity {
|
|||||||
ab.setDisplayHomeAsUpEnabled(true);
|
ab.setDisplayHomeAsUpEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
String link = "briar://" + getRandomString(64);
|
String link = "briar://" + getRandomBase32String(64);
|
||||||
|
|
||||||
TextView linkView = findViewById(R.id.linkView);
|
TextView linkView = findViewById(R.id.linkView);
|
||||||
linkView.setText(link);
|
linkView.setText(link);
|
||||||
|
|||||||
Reference in New Issue
Block a user