[Mono-list] Crypto Unit tests on linux

Paolo Molaro lupus@ximian.com
Wed, 16 Oct 2002 10:35:56 +0200

On 10/15/02 Sebastien Pouliot wrote:
> I found out that I made a cyclic dependency: some classes
> (AsymmetricAlgorithm, DSA, RSA) requires XmlDocument. And still the problem
> didn't show up until I tried a "make clean" (else it would just use the one
> present in System.Xml.Dll). These classes have been excluded from the build
> process (probably just because of this) but I wasn't aware of it. So this is
> the reason for the class library is compiling just fine.

corlib needs to be self-contained: you can't use types from any other
assembly in it, so you need to remove the use of XmlDocument from the
crypto classes.
You have two choices for the substitute code:
1) write a small xml parser that handles just the stuff you need
in corlib
2) (better, IMHO) write an internalcall that uses the GMarkup parser
in glib and fills in the RSA and DSA structures.

To do 2), you need to declare in the runtime header files two structures
that match the C# implementation of DSAParameters and RSAParameters.

typedef struct {
	MonoArray *P;
	MonoArray *Q;
	MonoArray *D;
	MonoArray *DP;
	MonoArray *DQ;
	MonoArray *InverseQ;
	MonoArray *Modulus;
	MonoArray *Exponent;
} MonoRSAParameters;

Then you write the two internalcalls as:

	static extern bool GetRSA (string xml, out RSAParameters rsap);
	static extern bool GetDSA (string xml, out DSAParameters rsap);

The C functions will look like:

CryptoGetRSA (MonoString *xml, MonoRSAParameters *rsap)
	GMarkupParseContext *context;
	char *p = mono_string_to_utf8 (xml);
	context = ...create markup context...;
	...parse and set the fields in rsap...
	g_free (p);
	if (parse_success)
		return TRUE;
	return FALSE;

mono/docs/internal-calls has some more info on registering the internal
call to the runtime.


lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better