All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: sfrench-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org
Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Subject: [PATCH 3/3] CIFS: Use linux/asn1.h
Date: Mon, 22 Oct 2012 15:23:41 +0100	[thread overview]
Message-ID: <20121022142340.6989.5702.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20121022142318.6989.5077.stgit-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>

Use linux/asn1.h in CIFS's ASN.1 decoder to get common ASN.1 constants rather
than redefining them for itself.

Signed-off-by: David Howells <dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---

 fs/cifs/asn1.c |   76 ++++++++++++++++++--------------------------------------
 1 file changed, 24 insertions(+), 52 deletions(-)

diff --git a/fs/cifs/asn1.c b/fs/cifs/asn1.c
index 3a7b2b6..2e46b81 100644
--- a/fs/cifs/asn1.c
+++ b/fs/cifs/asn1.c
@@ -22,6 +22,7 @@
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
+#include <linux/asn1.h>
 #include <linux/oid_registry.h>
 #include "cifspdu.h"
 #include "cifsglob.h"
@@ -34,40 +35,6 @@
  *
  *****************************************************************************/
 
-/* Class */
-#define ASN1_UNI	0	/* Universal */
-#define ASN1_APL	1	/* Application */
-#define ASN1_CTX	2	/* Context */
-#define ASN1_PRV	3	/* Private */
-
-/* Tag */
-#define ASN1_EOC	0	/* End Of Contents or N/A */
-#define ASN1_BOL	1	/* Boolean */
-#define ASN1_INT	2	/* Integer */
-#define ASN1_BTS	3	/* Bit String */
-#define ASN1_OTS	4	/* Octet String */
-#define ASN1_NUL	5	/* Null */
-#define ASN1_OJI	6	/* Object Identifier  */
-#define ASN1_OJD	7	/* Object Description */
-#define ASN1_EXT	8	/* External */
-#define ASN1_ENUM	10	/* Enumerated */
-#define ASN1_SEQ	16	/* Sequence */
-#define ASN1_SET	17	/* Set */
-#define ASN1_NUMSTR	18	/* Numerical String */
-#define ASN1_PRNSTR	19	/* Printable String */
-#define ASN1_TEXSTR	20	/* Teletext String */
-#define ASN1_VIDSTR	21	/* Video String */
-#define ASN1_IA5STR	22	/* IA5 String */
-#define ASN1_UNITIM	23	/* Universal Time */
-#define ASN1_GENTIM	24	/* General Time */
-#define ASN1_GRASTR	25	/* Graphical String */
-#define ASN1_VISSTR	26	/* Visible String */
-#define ASN1_GENSTR	27	/* General String */
-
-/* Primitive / Constructed methods*/
-#define ASN1_PRI	0	/* Primitive */
-#define ASN1_CON	1	/* Constructed */
-
 /*
  * Error codes.
  */
@@ -155,7 +122,8 @@ asn1_tag_decode(struct asn1_ctx *ctx, unsigned int *tag)
 
 static unsigned char
 asn1_id_decode(struct asn1_ctx *ctx,
-	       unsigned int *cls, unsigned int *con, unsigned int *tag)
+	       enum asn1_class *cls, enum asn1_method *con,
+	       enum asn1_tag *tag)
 {
 	unsigned char ch;
 
@@ -166,7 +134,7 @@ asn1_id_decode(struct asn1_ctx *ctx,
 	*con = (ch & 0x20) >> 5;
 	*tag = (ch & 0x1F);
 
-	if (*tag == 0x1F) {
+	if (*tag == ASN1_LONG_TAG) {
 		if (!asn1_tag_decode(ctx, tag))
 			return 0;
 	}
@@ -181,7 +149,7 @@ asn1_length_decode(struct asn1_ctx *ctx, unsigned int *def, unsigned int *len)
 	if (!asn1_octet_decode(ctx, &ch))
 		return 0;
 
-	if (ch == 0x80)
+	if (ch == ASN1_INDEFINITE_LENGTH)
 		*def = 0;
 	else {
 		*def = 1;
@@ -212,7 +180,8 @@ asn1_length_decode(struct asn1_ctx *ctx, unsigned int *def, unsigned int *len)
 static unsigned char
 asn1_header_decode(struct asn1_ctx *ctx,
 		   unsigned char **eoc,
-		   unsigned int *cls, unsigned int *con, unsigned int *tag)
+		   enum asn1_class *cls, enum asn1_method *con,
+		   enum asn1_tag *tag)
 {
 	unsigned int def = 0;
 	unsigned int len = 0;
@@ -224,7 +193,7 @@ asn1_header_decode(struct asn1_ctx *ctx,
 		return 0;
 
 	/* primitive shall be definite, indefinite shall be constructed */
-	if (*con == ASN1_PRI && !def)
+	if (*con == ASN1_PRIM && !def)
 		return 0;
 
 	if (def)
@@ -402,7 +371,10 @@ decode_negTokenInit(unsigned char *security_blob, int length,
 	struct asn1_ctx ctx;
 	unsigned char *end;
 	unsigned char *sequence_end;
-	unsigned int cls, con, tag, rc;
+	unsigned int rc;
+	enum asn1_class cls;
+	enum asn1_method con;
+	enum asn1_tag tag;
 
 	/* cifs_dump_mem(" Received SecBlob ", security_blob, length); */
 
@@ -412,7 +384,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
 	if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
 		cFYI(1, "Error decoding negTokenInit header");
 		return 0;
-	} else if ((cls != ASN1_APL) || (con != ASN1_CON)
+	} else if ((cls != ASN1_APPL) || (con != ASN1_CONS)
 		   || (tag != ASN1_EOC)) {
 		cFYI(1, "cls = %d con = %d tag = %d", cls, con, tag);
 		return 0;
@@ -421,8 +393,8 @@ decode_negTokenInit(unsigned char *security_blob, int length,
 	/* Check for SPNEGO OID -- remember to free obj->oid */
 	rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag);
 	if (rc) {
-		if ((tag == ASN1_OJI) && (con == ASN1_PRI) &&
-		    (cls == ASN1_UNI)) {
+		if ((tag == ASN1_OID) && (con == ASN1_PRIM) &&
+		    (cls == ASN1_UNIV)) {
 			if (asn1_oid_decode(&ctx, end) != OID_SPNEGO)
 				rc = 0;
 		} else
@@ -439,7 +411,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
 	if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
 		cFYI(1, "Error decoding negTokenInit");
 		return 0;
-	} else if ((cls != ASN1_CTX) || (con != ASN1_CON)
+	} else if ((cls != ASN1_CONT) || (con != ASN1_CONS)
 		   || (tag != ASN1_EOC)) {
 		cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 0",
 		     cls, con, tag, end, *end);
@@ -450,7 +422,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
 	if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
 		cFYI(1, "Error decoding negTokenInit");
 		return 0;
-	} else if ((cls != ASN1_UNI) || (con != ASN1_CON)
+	} else if ((cls != ASN1_UNIV) || (con != ASN1_CONS)
 		   || (tag != ASN1_SEQ)) {
 		cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 1",
 		     cls, con, tag, end, *end);
@@ -461,7 +433,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
 	if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
 		cFYI(1, "Error decoding 2nd part of negTokenInit");
 		return 0;
-	} else if ((cls != ASN1_CTX) || (con != ASN1_CON)
+	} else if ((cls != ASN1_CONT) || (con != ASN1_CONS)
 		   || (tag != ASN1_EOC)) {
 		cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 0",
 		     cls, con, tag, end, *end);
@@ -473,7 +445,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
 	    (&ctx, &sequence_end, &cls, &con, &tag) == 0) {
 		cFYI(1, "Error decoding 2nd part of negTokenInit");
 		return 0;
-	} else if ((cls != ASN1_UNI) || (con != ASN1_CON)
+	} else if ((cls != ASN1_UNIV) || (con != ASN1_CONS)
 		   || (tag != ASN1_SEQ)) {
 		cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 1",
 		     cls, con, tag, end, *end);
@@ -487,7 +459,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
 			cFYI(1, "Error decoding negTokenInit hdr exit2");
 			return 0;
 		}
-		if ((tag == ASN1_OJI) && (con == ASN1_PRI)) {
+		if ((tag == ASN1_OID) && (con == ASN1_PRIM)) {
 			enum OID oid = asn1_oid_decode(&ctx, end);
 			if (oid != OID__NR)
 				cFYI(1, "OID oid = %u", oid);
@@ -524,7 +496,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
 			goto decode_negtoken_exit;
 		cFYI(1, "Error decoding last part negTokenInit exit3");
 		return 0;
-	} else if ((cls != ASN1_CTX) || (con != ASN1_CON)) {
+	} else if ((cls != ASN1_CONT) || (con != ASN1_CONS)) {
 		/* tag = 3 indicating mechListMIC */
 		cFYI(1, "Exit 4 cls = %d con = %d tag = %d end = %p (%d)",
 			cls, con, tag, end, *end);
@@ -535,7 +507,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
 	if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
 		cFYI(1, "Error decoding last part negTokenInit exit5");
 		return 0;
-	} else if ((cls != ASN1_UNI) || (con != ASN1_CON)
+	} else if ((cls != ASN1_UNIV) || (con != ASN1_CONS)
 		   || (tag != ASN1_SEQ)) {
 		cFYI(1, "cls = %d con = %d tag = %d end = %p (%d)",
 			cls, con, tag, end, *end);
@@ -545,7 +517,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
 	if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
 		cFYI(1, "Error decoding last part negTokenInit exit 7");
 		return 0;
-	} else if ((cls != ASN1_CTX) || (con != ASN1_CON)) {
+	} else if ((cls != ASN1_CONT) || (con != ASN1_CONS)) {
 		cFYI(1, "Exit 8 cls = %d con = %d tag = %d end = %p (%d)",
 			cls, con, tag, end, *end);
 		return 0;
@@ -555,7 +527,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
 	if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
 		cFYI(1, "Error decoding last part negTokenInit exit9");
 		return 0;
-	} else if ((cls != ASN1_UNI) || (con != ASN1_PRI)
+	} else if ((cls != ASN1_UNIV) || (con != ASN1_PRIM)
 		   || (tag != ASN1_GENSTR)) {
 		cFYI(1, "Exit10 cls = %d con = %d tag = %d end = %p (%d)",
 			cls, con, tag, end, *end);

  parent reply	other threads:[~2012-10-22 14:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-22 14:23 [RFC][PATCH 0/3] CIFS: Use OID registry and ASN.1 header David Howells
     [not found] ` <20121022142318.6989.5077.stgit-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2012-10-22 14:23   ` [PATCH 1/3] CIFS: Use OID registry facility David Howells
     [not found]     ` <CADT32eKTZTQw70Wu2gvqF6yorKqEoA=1m0SP=QkGqieaSEFbQQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-22 19:13       ` David Howells
     [not found]         ` <12049.1350933186-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2012-10-22 19:57           ` Shirish Pargaonkar
     [not found]         ` <CADT32eK73Y9dxsGJba1Nuxyp7_4iYk_yeQe_GY1ztCDVwZT04g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-27 13:04           ` David Howells
     [not found]             ` <11913.1351343061-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2012-10-27 22:53               ` Shirish Pargaonkar
     [not found]     ` <20121022143635.0ee0c824-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org>
2012-10-22 19:19       ` David Howells
     [not found]         ` <12137.1350933565-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2012-10-22 19:57           ` Jeff Layton
     [not found]     ` <20121022142326.6989.45552.stgit-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2012-10-22 18:36       ` Jeff Layton
2012-10-22 18:48       ` Shirish Pargaonkar
2012-10-28 11:22       ` Jeff Layton
2012-10-22 14:23   ` [PATCH 2/3] ASN.1: Define indefinite length marker constant David Howells
     [not found]     ` <20121022142333.6989.61832.stgit-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2012-10-22 18:40       ` Jeff Layton
     [not found]     ` <20121022144021.1b1a3135-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org>
2012-10-22 19:09       ` David Howells
2012-10-22 14:23   ` David Howells [this message]
     [not found]     ` <20121022142340.6989.5702.stgit-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2012-10-22 18:38       ` [PATCH 3/3] CIFS: Use linux/asn1.h Jeff Layton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121022142340.6989.5702.stgit@warthog.procyon.org.uk \
    --to=dhowells-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=sfrench-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.