From ae6bab4b284b89b78dfd1174d62e5690a4648add Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Tue, 11 May 2010 12:42:46 +0000
Subject: [PATCH] SAML2: Add createKeyDescriptor() helper-function.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2291 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SAML2/Utils.php | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/lib/SAML2/Utils.php b/lib/SAML2/Utils.php
index cd7a323ac..a63f97612 100644
--- a/lib/SAML2/Utils.php
+++ b/lib/SAML2/Utils.php
@@ -469,4 +469,29 @@ class SAML2_Utils {
 		}
 	}
 
+
+	/**
+	 * Create a KeyDescriptor with the given certificate.
+	 *
+	 * @param string $x509Data  The certificate, as a base64-encoded DER data.
+	 * @return SAML2_XML_md_KeyDescriptor  The keydescriptor.
+	 */
+	public static function createKeyDescriptor($x509Data) {
+		assert('is_string($x509Data)');
+
+		$x509Certificate = new SAML2_XML_ds_X509Certificate();
+		$x509Certificate->certificate = $x509Data;
+
+		$x509Data = new SAML2_XML_ds_X509Data();
+		$x509Data->data[] = $x509Certificate;
+
+		$keyInfo = new SAML2_XML_ds_KeyInfo();
+		$keyInfo->info[] = $x509Data;
+
+		$keyDescriptor = new SAML2_XML_md_KeyDescriptor();
+		$keyDescriptor->KeyInfo = $keyInfo;
+
+		return $keyDescriptor;
+	}
+
 }
-- 
GitLab