diff --git a/pem.py b/pem.py
index <HASH>..<HASH> 100644
--- a/pem.py
+++ b/pem.py
@@ -61,16 +61,8 @@ def parse_file(file_name):
         return parse(f.read())
 
 
-def certificateOptionsFromFiles(*pemFiles, **kw):
-    """
-    Read all *pemFiles*, find one key, use the first certificate as server
-    certificate and the rest as chain.
-    """
+def certificateOptionsFromPEMs(pems, **kw):
     from twisted.internet import ssl
-
-    pems = []
-    for pemFile in pemFiles:
-        pems += parse_file(pemFile)
     keys = [key for key in pems if isinstance(key, Key)]
     if not len(keys):
         raise ValueError('Supplied PEM file(s) do *not* contain a key.')
@@ -99,6 +91,17 @@ def certificateOptionsFromFiles(*pemFiles, **kw):
         return ctxFactory
 
 
+def certificateOptionsFromFiles(*pemFiles, **kw):
+    """
+    Read all *pemFiles*, find one key, use the first certificate as server
+    certificate and the rest as chain.
+    """
+    pems = []
+    for pemFile in pemFiles:
+        pems += parse_file(pemFile)
+    return certificateOptionsFromPEMs(pems, **kw)
+
+
 class _DHParamContextFactory(object):
     """
     A wrapping context factory that gets a context from a different
Refactor to allow working with pem objects directly, file I/O is a separate concern.