[pkg-opensc-commit] [opensc] 47/295: libopensc: cache EF.ODF and EF.TokenInfo

Eric Dorland eric at moszumanska.debian.org
Sat Jun 24 21:11:14 UTC 2017


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository opensc.

commit 21fd6f0d95d7ec06609a964f1cd3ce8675476bee
Author: Frank Morgner <frankmorgner at gmail.com>
Date:   Mon Jun 20 13:12:27 2016 +0200

    libopensc: cache EF.ODF and EF.TokenInfo
---
 src/libopensc/pkcs15.c | 62 ++++++++++++++++++++++++++++++++++----------------
 1 file changed, 43 insertions(+), 19 deletions(-)

diff --git a/src/libopensc/pkcs15.c b/src/libopensc/pkcs15.c
index a525971..ddfe5f9 100644
--- a/src/libopensc/pkcs15.c
+++ b/src/libopensc/pkcs15.c
@@ -1074,17 +1074,28 @@ sc_pkcs15_bind_internal(struct sc_pkcs15_card *p15card, struct sc_aid *aid)
 	if(buf == NULL)
 		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
 
-	err = sc_read_binary(card, 0, buf, len, 0);
-	if (err < 0)   {
-		sc_log(ctx, "read EF(ODF) file error: %s", sc_strerror(err));
-		goto end;
-	}
-	else if (err < 2) {
-		err = SC_ERROR_PKCS15_APP_NOT_FOUND;
-		sc_log(ctx, "Invalid content of EF(ODF): %s", sc_strerror(err));
-		goto end;
+	err = -1; /* file state: not in cache */
+	if (p15card->opts.use_file_cache) {
+		err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
+		if (err == SC_SUCCESS)
+			err = len;
+	}
+	if (err < 0) {
+		err = sc_read_binary(card, 0, buf, len, 0);
+		if (err < 0)   {
+			sc_log(ctx, "read EF(ODF) file error: %s", sc_strerror(err));
+			goto end;
+		}
+		else if (err < 2) {
+			err = SC_ERROR_PKCS15_APP_NOT_FOUND;
+			sc_log(ctx, "Invalid content of EF(ODF): %s", sc_strerror(err));
+			goto end;
+		}
+
+		if (p15card->opts.use_file_cache) {
+			sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
+		}
 	}
-	len = err;
 
 	if (parse_odf(buf, len, p15card)) {
 		err = SC_ERROR_PKCS15_APP_NOT_FOUND;
@@ -1129,15 +1140,28 @@ sc_pkcs15_bind_internal(struct sc_pkcs15_card *p15card, struct sc_aid *aid)
 	if(buf == NULL)
 		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
 
-	err = sc_read_binary(card, 0, buf, len, 0);
-	if (err < 0)   {
-		sc_log(ctx, "read EF(TokenInfo) file error: %s", sc_strerror(err));
-		goto end;
-	}
-	if (err <= 2) {
-		err = SC_ERROR_PKCS15_APP_NOT_FOUND;
-		sc_log(ctx, "Invalid content of EF(TokenInfo): %s", sc_strerror(err));
-		goto end;
+	err = -1; /* file state: not in cache */
+	if (p15card->opts.use_file_cache) {
+		err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
+		if (err == SC_SUCCESS)
+			err = len;
+	}
+	if (err < 0) {
+		err = sc_read_binary(card, 0, buf, len, 0);
+		if (err < 0)   {
+			sc_log(ctx, "read EF(TokenInfo) file error: %s", sc_strerror(err));
+			goto end;
+		}
+		if (err <= 2) {
+			err = SC_ERROR_PKCS15_APP_NOT_FOUND;
+			sc_log(ctx, "Invalid content of EF(TokenInfo): %s", sc_strerror(err));
+			goto end;
+		}
+
+		if (p15card->opts.use_file_cache) {
+			sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
+		}
+		err = len;
 	}
 
 	memset(&tokeninfo, 0, sizeof(tokeninfo));

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/opensc.git



More information about the pkg-opensc-commit mailing list