// Path: wallet_lib/src/main/java/de/uni_bonn/bit/wallet_protocol/QRCodeData.java
// public class QRCodeData{
//     List<String> ipAddresses;
//     byte[] publicKey;
// 
//     public QRCodeData() {} //for serialization
// 
//     public QRCodeData(List<String> ipAddresses, PublicKey publicKey) {
//         this.ipAddresses = ipAddresses;
//         setPublicKey(publicKey);
//     }
// 
//     public List<String> getIpAddresses() {
//         return ipAddresses;
//     }
// 
//     public void setIpAddresses(List<String> ipAddresses) {
//         this.ipAddresses = ipAddresses;
//     }
// 
//     public PublicKey getPublicKey() throws NoSuchAlgorithmException, InvalidKeySpecException {
//         return KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(this.publicKey));
//     }
// 
//     public void setPublicKey(PublicKey publicKey) {
//         this.publicKey = publicKey.getEncoded();
//     }
// }


import org.bitcoinj.core.Base58;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import de.uni_bonn.bit.wallet_protocol.QRCodeData;
import org.apache.avro.io.Encoder;
import org.apache.avro.io.EncoderFactory;
import org.apache.avro.reflect.ReflectDatumWriter;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.PublicKey;
import java.util.List;
/*
* Copyright 2014 Christopher Mann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.uni_bonn.bit;




/**
 * This class contains some helper methods to create a QRCode which contains some given data.
 */
public class QRCodeHelper {

    /**
     * This methods creates a QRCode which contains a list of IP addresses and a public key for a TLS connection. The
     * data is serialized with avro and then Base58 encoded. The resulting string is then stored inside the QR code which
     * is returned as a {@link java.awt.image.BufferedImage}.
     */
    public static BufferedImage CreateQRCodeForTLSSetup(List<String> ipAddresses, PublicKey publicKey) throws IOException, WriterException {
// Path: wallet_lib/src/main/java/de/uni_bonn/bit/wallet_protocol/QRCodeData.java
// public class QRCodeData{
//     List<String> ipAddresses;
//     byte[] publicKey;
// 
//     public QRCodeData() {} //for serialization
// 
//     public QRCodeData(List<String> ipAddresses, PublicKey publicKey) {
//         this.ipAddresses = ipAddresses;
//         setPublicKey(publicKey);
//     }
// 
//     public List<String> getIpAddresses() {
//         return ipAddresses;
//     }
// 
//     public void setIpAddresses(List<String> ipAddresses) {
//         this.ipAddresses = ipAddresses;
//     }
// 
//     public PublicKey getPublicKey() throws NoSuchAlgorithmException, InvalidKeySpecException {
//         return KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(this.publicKey));
//     }
// 
//     public void setPublicKey(PublicKey publicKey) {
//         this.publicKey = publicKey.getEncoded();
//     }
// }


// Path: desktop_wallet/src/main/java/de/uni_bonn/bit/QRCodeHelper.java
import org.bitcoinj.core.Base58;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import de.uni_bonn.bit.wallet_protocol.QRCodeData;
import org.apache.avro.io.Encoder;
import org.apache.avro.io.EncoderFactory;
import org.apache.avro.reflect.ReflectDatumWriter;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.PublicKey;
import java.util.List;

/*
* Copyright 2014 Christopher Mann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.uni_bonn.bit;




/**
 * This class contains some helper methods to create a QRCode which contains some given data.
 */
public class QRCodeHelper {

    /**
     * This methods creates a QRCode which contains a list of IP addresses and a public key for a TLS connection. The
     * data is serialized with avro and then Base58 encoded. The resulting string is then stored inside the QR code which
     * is returned as a {@link java.awt.image.BufferedImage}.
     */
    public static BufferedImage CreateQRCodeForTLSSetup(List<String> ipAddresses, PublicKey publicKey) throws IOException, WriterException {
        ReflectDatumWriter<QRCodeData> specificDatumWriter = new ReflectDatumWriter<>(QRCodeData.class);