SHA256
Исправить восстановление сессии после переподключения
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
-- SHiNE v41: public channel avatars now use BitTorrent v2 PR (Base58), no SHA256 legacy.
|
||||
BEGIN;
|
||||
ALTER TABLE channel_names_state RENAME COLUMN ava_sha256 TO ava_pr;
|
||||
-- Old sha256 hex values cannot be used as Pieces Root; no automatic conversion exists.
|
||||
UPDATE channel_names_state SET ava_pr = '', ava_ar = '', ava_size = 0 WHERE ava_pr <> '';
|
||||
UPDATE db_schema_version SET schema_version = 41 WHERE id = 1;
|
||||
COMMIT;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package server.logic.ws_protocol.JSON.handlers.avatars;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** Canonical 32-byte BitTorrent v2 pieces root encoded as Bitcoin Base58. */
|
||||
public final class PiecesRootValidator {
|
||||
private static final String ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||
private static final Pattern B58 = Pattern.compile("^[1-9A-HJ-NP-Za-km-z]{32,44}$");
|
||||
private PiecesRootValidator() {}
|
||||
public static boolean valid(String root) {
|
||||
if (root == null || !B58.matcher(root).matches()) return false;
|
||||
int leadingZeros = 0;
|
||||
while (leadingZeros < root.length() && root.charAt(leadingZeros) == '1') leadingZeros++;
|
||||
BigInteger value = BigInteger.ZERO;
|
||||
for (int i = leadingZeros; i < root.length(); i++) {
|
||||
int digit = ALPHABET.indexOf(root.charAt(i));
|
||||
if (digit < 0) return false;
|
||||
value = value.multiply(BigInteger.valueOf(58)).add(BigInteger.valueOf(digit));
|
||||
}
|
||||
int dataBytes = value.signum() == 0 ? 0 : (value.bitLength() + 7) / 8;
|
||||
return leadingZeros + dataBytes == 32;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user