package com.airlock.iam.saml2.infrastructure.state;

import com.airlock.iam.base.api.domain.model.exception.FailureException;
import com.sun.identity.saml2.common.SAML2Exception;
import com.sun.identity.saml2.protocol.Response;
import com.sun.identity.saml2.protocol.impl.ResponseImpl;

final class ResponseSerializer implements Serializer<Response> {
   public String mapToStore(Response value) {
      try {
         return value.toXMLString(true, true);
      } catch (SAML2Exception e) {
         throw new FailureException(e);
      }
   }

   public Response mapFromStore(String xmlString) {
      try {
         return new ResponseImpl(xmlString, false);
      } catch (SAML2Exception e) {
         throw new FailureException(e);
      }
   }
}
