// File: /workspace/github_cpp_makefile_star2_O3/luigix25[P]SSLP/library/CertificateManager.cpp
// Function: CertificateManager::CertificateManager(char const*, char const*)
CertificateManager::CertificateManager(const char *ca_cert_path, const char *ca_crl_path){

	int ret;
	
	//Load ca_cert
	FILE* cacert_file = fopen(ca_cert_path, "r");
	if(!cacert_file){ cerr << "Error: cannot open file '" << ca_cert_path << "' (missing?)\n"; exit(1); }
	X509* cacert = PEM_read_X509(cacert_file, NULL, NULL, NULL);
	fclose(cacert_file);
	if(!cacert){ cerr << "Error: PEM_read_X509 returned NULL\n"; exit(1); }

	//Load ca_crl
	FILE* crl_file = fopen(ca_crl_path, "r");
	if(!crl_file){ cerr << "Error: cannot open file '" << ca_crl_path << "' (missing?)\n"; exit(1); }
	X509_CRL* crl = PEM_read_X509_CRL(crl_file, NULL, NULL, NULL);
	fclose(crl_file);
	if(!crl){ cerr << "Error: PEM_read_X509_CRL returned NULL\n"; exit(1); }
	
	//Creating the store
	this->store = X509_STORE_new();
	if(!this->store) { cerr << "Error: X509_STORE_new returned NULL\n" << ERR_error_string(ERR_get_error(), NULL) << "\n"; exit(1); }
	ret = X509_STORE_add_cert(this->store, cacert);
	if(ret != 1) { cerr << "Error: X509_STORE_add_cert returned " << ret << "\n" << ERR_error_string(ERR_get_error(), NULL) << "\n"; exit(1); }
	ret = X509_STORE_add_crl(this->store, crl);
	if(ret != 1) { cerr << "Error: X509_STORE_add_crl returned " << ret << "\n" << ERR_error_string(ERR_get_error(), NULL) << "\n"; exit(1); }
	ret = X509_STORE_set_flags(this->store, X509_V_FLAG_CRL_CHECK);
	if(ret != 1) { cerr << "Error: X509_STORE_set_flags returned " << ret << "\n" << ERR_error_string(ERR_get_error(), NULL) << "\n"; exit(1); }

	X509_free(cacert);
	X509_CRL_free(crl);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x1c91(%rip), %rsi      # 0xb329
movq %r14, %rdi
callq 0x4510
testq %rax, %rax
je 0x9772
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4610
movq %rax, %r14
movq %r12, %rdi
callq 0x4430
testq %r14, %r14
je 0x978d
leaq 0x1c54(%rip), %rsi      # 0xb329
movq %r15, %rdi
callq 0x4510
testq %rax, %rax
je 0x97a0
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4890
movq %rax, %r15
movq %r12, %rdi
callq 0x4430
testq %r15, %r15
je 0x97c7
callq 0x4500
movq %rax, (%rbx)
testq %rax, %rax
je 0x97da
movq %rax, %rdi
movq %r14, %rsi
callq 0x4240
cmpl $0x1, %eax
jne 0x9819
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x4710
cmpl $0x1, %eax
jne 0x982b
movq (%rbx), %rdi
movl $0x4, %esi
callq 0x4330
cmpl $0x1, %eax
jne 0x9847
movq %r14, %rdi
callq 0x4210
movq %r15, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x41d0
movq 0x686f(%rip), %rdi      # 0xffe8
leaq 0x1acb(%rip), %rsi      # 0xb24b
callq 0x4420
movq %rax, %rdi
movq %r14, %rsi
jmp 0x97b9
movq 0x6854(%rip), %rdi      # 0xffe8
leaq 0x1ad8(%rip), %rsi      # 0xb273
jmp 0x989b
movq 0x6841(%rip), %rdi      # 0xffe8
leaq 0x1a9d(%rip), %rsi      # 0xb24b
callq 0x4420
movq %rax, %rdi
movq %r15, %rsi
callq 0x4420
leaq 0x1aa0(%rip), %rsi      # 0xb265
jmp 0x9811
movq 0x681a(%rip), %rdi      # 0xffe8
leaq 0x2005(%rip), %rsi      # 0xb7da
jmp 0x989b
movq 0x6807(%rip), %rdi      # 0xffe8
leaq 0x201a(%rip), %rsi      # 0xb802
callq 0x4420
movq %rax, %rbx
callq 0x4600
movq %rax, %rdi
xorl %esi, %esi
callq 0x4160
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4420
leaq 0x1a60(%rip), %rsi      # 0xb271
movq %rax, %rdi
jmp 0x989b
movl %eax, %ebp
movq 0x67c6(%rip), %rdi      # 0xffe8
leaq 0x1ffe(%rip), %rsi      # 0xb827
jmp 0x983b
movl %eax, %ebp
movq 0x67b4(%rip), %rdi      # 0xffe8
leaq 0x2011(%rip), %rsi      # 0xb84c
callq 0x4420
movq %rax, %rdi
movl %ebp, %esi
jmp 0x9861
movl %eax, %ebx
movq 0x6798(%rip), %rdi      # 0xffe8
leaq 0x2019(%rip), %rsi      # 0xb870
callq 0x4420
movq %rax, %rdi
movl %ebx, %esi
callq 0x4790
leaq 0x1a04(%rip), %rbx      # 0xb271
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4420
movq %rax, %r14
callq 0x4600
movq %rax, %rdi
xorl %esi, %esi
callq 0x4160
movq %r14, %rdi
movq %rax, %rsi
callq 0x4420
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4420
movl $0x1, %edi
callq 0x4560