Package ca.carleton.gcrc.couch.user.token

Source Code of ca.carleton.gcrc.couch.user.token.TokenDecoder

package ca.carleton.gcrc.couch.user.token;

import ca.carleton.gcrc.security.ber.BerConstructed;
import ca.carleton.gcrc.security.ber.BerObject;
import ca.carleton.gcrc.security.ber.encoding.BerDecoder;

public class TokenDecoder {

  public Token decode(byte[] encodedToken) throws Exception {
    try {
      BerObject outerObj = BerDecoder.decode(encodedToken);
     
      if( false == outerObj.isTypeConstructed()
       || false == (outerObj instanceof BerConstructed) ){
        throw new Exception("Object is not constructed.");
      }
      BerConstructed outer = (BerConstructed)outerObj;

      if( Token.APPLICATION_TYPE_CREATION == outer.getType() ){
        return CreationToken.decode(outer);
      } else {
        throw new Exception("Unrecognized type: "+outer.getType());
      }
     
    } catch(Exception e) {
      throw new Exception("Error while deccoding token", e);
    }
  }
}
TOP

Related Classes of ca.carleton.gcrc.couch.user.token.TokenDecoder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.