Just for fun: added QR code of identity to log file
This commit is contained in:
parent
21b0e64130
commit
1a52af880d
@ -49,6 +49,8 @@ dependencies {
|
|||||||
|
|
||||||
compile 'com.h2database:h2:1.4.194'
|
compile 'com.h2database:h2:1.4.194'
|
||||||
|
|
||||||
|
compile 'com.google.zxing:core:3.3.0'
|
||||||
|
|
||||||
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
|
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
|
||||||
testCompile("org.springframework.boot:spring-boot-starter-test")
|
testCompile("org.springframework.boot:spring-boot-starter-test")
|
||||||
}
|
}
|
||||||
|
@ -204,6 +204,7 @@ public class JabitServerConfig {
|
|||||||
LOG.info("Using " + identity);
|
LOG.info("Using " + identity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LOG.info("QR Code:\n" + Utils.qrCode(identity));
|
||||||
return identity;
|
return identity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,16 +16,24 @@
|
|||||||
|
|
||||||
package ch.dissem.bitmessage.server;
|
package ch.dissem.bitmessage.server;
|
||||||
|
|
||||||
import java.io.File;
|
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||||
import java.io.FileNotFoundException;
|
import com.google.zxing.WriterException;
|
||||||
import java.io.FileWriter;
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||||
import java.io.IOException;
|
import com.google.zxing.qrcode.encoder.ByteMatrix;
|
||||||
|
import com.google.zxing.qrcode.encoder.Encoder;
|
||||||
|
import com.google.zxing.qrcode.encoder.QRCode;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
|
||||||
|
|
||||||
public static Set<String> readOrCreateList(String filename, String content) {
|
public static Set<String> readOrCreateList(String filename, String content) {
|
||||||
try {
|
try {
|
||||||
File file = new File(filename);
|
File file = new File(filename);
|
||||||
@ -76,6 +84,67 @@ public class Utils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String qrCode(BitmessageAddress address) {
|
||||||
|
StringBuilder link = new StringBuilder();
|
||||||
|
link.append("bitmessage:");
|
||||||
|
link.append(address.getAddress());
|
||||||
|
if (address.getAlias() != null) {
|
||||||
|
link.append("?label=").append(address.getAlias());
|
||||||
|
}
|
||||||
|
if (address.getPubkey() != null) {
|
||||||
|
link.append(address.getAlias() == null ? '?' : '&');
|
||||||
|
ByteArrayOutputStream pubkey = new ByteArrayOutputStream();
|
||||||
|
try {
|
||||||
|
address.getPubkey().writeUnencrypted(pubkey);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
// This makes the QR code quite big, so it's not active. But sometimes it might be useful:
|
||||||
|
// link.append("pubkey=").append(Base64.getUrlEncoder().encodeToString(pubkey.toByteArray()));
|
||||||
|
}
|
||||||
|
QRCode code;
|
||||||
|
try {
|
||||||
|
code = Encoder.encode(link.toString(), ErrorCorrectionLevel.L, null);
|
||||||
|
} catch (WriterException e) {
|
||||||
|
LOG.error(e.getMessage(), e);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
ByteMatrix matrix = code.getMatrix();
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (int i=0; i<2; i++){
|
||||||
|
for (int j=0;j<matrix.getWidth()+8; j++){
|
||||||
|
result.append('█');
|
||||||
|
}
|
||||||
|
result.append('\n');
|
||||||
|
}
|
||||||
|
for (int i = 0; i < matrix.getHeight(); i += 2) {
|
||||||
|
result.append("████");
|
||||||
|
for (int j = 0; j < matrix.getWidth(); j++) {
|
||||||
|
if (matrix.get(i, j) > 0) {
|
||||||
|
if (matrix.getHeight() > i + 1 && matrix.get(i + 1, j) > 0) {
|
||||||
|
result.append(' ');
|
||||||
|
} else {
|
||||||
|
result.append('▄');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (matrix.getHeight() > i + 1 && matrix.get(i + 1, j) > 0) {
|
||||||
|
result.append('▀');
|
||||||
|
} else {
|
||||||
|
result.append('█');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.append("████\n");
|
||||||
|
}
|
||||||
|
for (int i=0; i<2; i++){
|
||||||
|
for (int j=0;j<matrix.getWidth()+8; j++){
|
||||||
|
result.append('█');
|
||||||
|
}
|
||||||
|
result.append('\n');
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean zero(byte[] nonce) {
|
public static boolean zero(byte[] nonce) {
|
||||||
for (byte b : nonce) {
|
for (byte b : nonce) {
|
||||||
if (b != 0) return false;
|
if (b != 0) return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user