package a.b.a.i;

import android.text.TextUtils;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;
import com.share.connect.Device;
import java.io.IOException;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class b {
    public static final String g = "SHA256withRSA";
    private static final int h = 1;
    private static final String i = "public_key";
    private static final String j = "CarVerificationData";
    private static final String k = "short_name";
    private static final String l = "vendor_id";
    private static final String m = "vendor_name";
    private static final String n = "product_id";
    private static final String o = "product_name";
    @SerializedName("content")

    /* renamed from: a  reason: collision with root package name */
    private byte[] f30a;
    @SerializedName("signature")
    private byte[] b;
    @SerializedName("version")
    private int c;
    @SerializedName("cryptoConfigIndex")
    private String d;
    @SerializedName("SignAlgorithm")
    private String e;
    @SerializedName("salt")
    private String f;

    public static final class a {

        /* renamed from: a  reason: collision with root package name */
        private Reader f31a;

        public a a(Reader reader) {
            this.f31a = reader;
            return this;
        }

        public b a() {
            if (this.f31a != null) {
                String b = b();
                if (TextUtils.isEmpty(b)) {
                    return null;
                }
                return (b) new Gson().fromJson(new String(Base64.getDecoder().decode(b), StandardCharsets.UTF_8), b.class);
            }
            throw new IllegalArgumentException("Reader is null");
        }

        public String b() {
            if (this.f31a != null) {
                StringBuilder sb = new StringBuilder();
                try {
                    char[] cArr = new char[1024];
                    while (true) {
                        int read = this.f31a.read(cArr);
                        if (read <= 0) {
                            return sb.toString().trim();
                        }
                        sb.append(cArr, 0, read);
                    }
                } catch (IOException e) {
                    a.a.a.b.b(b.j, " read car verification data exception ", e);
                    return null;
                }
            } else {
                a.a.a.b.b(b.j, "CarVerificationData  no reader to build");
                throw new IllegalArgumentException("Reader is null");
            }
        }
    }

    private b() {
    }

    public Device a() {
        try {
            JsonObject asJsonObject = JsonParser.parseString(new String(this.f30a, StandardCharsets.UTF_8)).getAsJsonObject();
            Device device = new Device();
            device.setShortName(asJsonObject.get(k).getAsString());
            device.setVid(asJsonObject.get(l).getAsString());
            device.setVName(asJsonObject.get(m).getAsString());
            device.setPid(asJsonObject.get(n).getAsString());
            device.setPName(asJsonObject.get(o).getAsString());
            return device;
        } catch (Exception e2) {
            a.a.a.b.b(j, "getCarDevice exception ", e2);
            return null;
        }
    }

    public boolean b() {
        byte[] bArr;
        byte[] bArr2 = this.f30a;
        return bArr2 != null && bArr2.length > 0 && (bArr = this.b) != null && bArr.length > 0 && !TextUtils.isEmpty(this.d) && this.c > 0;
    }
}
