code: def create_signed_entity_descriptor(entity_descriptor, security_context, valid_for=None):
      
      if valid_for:
          entity_descriptor.valid_until = in_a_while(hours=valid_for)
  
      entity_desc, xmldoc = sign_entity_descriptor(entity_descriptor, None, security_context)
  
      if not valid_instance(entity_desc):
          raise ValueError("Could not construct valid EntityDescriptor tag")
  
      return xmldoc
docs: :param entity_descriptor: the entity descriptor to sign
      :param security_context: security context for the signature
      :param valid_for: number of hours the metadata should be valid
      :return: the signed XML document
  
      :type entity_descriptor: saml2.md.EntityDescriptor]
      :type security_context: saml2.sigver.SecurityContext
      :type valid_for: Optional[int]