Exemplo n.º 1
0
void AuthenticatedSymmetricCipherBase::ProcessData(byte *outString, const byte *inString, size_t length)
{
	m_totalMessageLength += length;
	if (m_state >= State_IVSet && m_totalMessageLength > MaxMessageLength())
		throw InvalidArgument(AlgorithmName() + ": message length exceeds maximum");

reswitch:
	switch (m_state)
	{
	case State_Start:
	case State_KeySet:
		throw BadState(AlgorithmName(), "ProcessData", "setting key and IV");
	case State_AuthFooter:
		throw BadState(AlgorithmName(), "ProcessData was called after footer input has started");
	case State_IVSet:
		AuthenticateLastHeaderBlock();
		m_bufferedDataLength = 0;
		m_state = AuthenticationIsOnPlaintext()==IsForwardTransformation() ? State_AuthUntransformed : State_AuthTransformed;
		goto reswitch;
	case State_AuthUntransformed:
		AuthenticateData(inString, length);
		AccessSymmetricCipher().ProcessData(outString, inString, length);
		break;
	case State_AuthTransformed:
		AccessSymmetricCipher().ProcessData(outString, inString, length);
		AuthenticateData(outString, length);
		break;
	default:
		CRYPTOPP_ASSERT(false);
	}
}
unsigned int	SimFilterWheel::currentPosition() {
	checkstate();
	if (_currentstate != FilterWheel::idle) {
		throw BadState("filterwheel not idle");
	}
	return _currentposition;
}
Exemplo n.º 3
0
void AuthenticatedSymmetricCipherBase::Update(const byte *input, size_t length)
{
	if (length == 0)
		return;

	switch (m_state)
	{
	case State_Start:
	case State_KeySet:
		throw BadState(AlgorithmName(), "Update", "setting key and IV");
	case State_IVSet:
		AuthenticateData(input, length);
		m_totalHeaderLength += length;
		break;
	case State_AuthUntransformed:
	case State_AuthTransformed:
		AuthenticateLastConfidentialBlock();
		m_bufferedDataLength = 0;
		m_state = State_AuthFooter;
		// fall through
	case State_AuthFooter:
		AuthenticateData(input, length);
		m_totalFooterLength += length;
		break;
	default:
		CRYPTOPP_ASSERT(false);
	}
}
Exemplo n.º 4
0
/**
 * \brief Start a calibration for a given focal length
 *
 * The focal length is the only piece of information that we can not
 * get from anywhere else, so it has to be specified
 */
Ice::Int GuiderI::startCalibration(ControlType caltype,
                                   const Ice::Current& /* current */) {
    debug(LOG_DEBUG, DEBUG_LOG, 0, "start calibration, type = %s",
          calibrationtype2string(caltype).c_str());

    // construct a tracker
    astro::guiding::TrackerPtr	tracker = getTracker();

    // start the calibration
    switch (caltype) {
    case ControlGuidePort:
        astro::event(EVENT_CLASS, astro::events::Event::GUIDE,
                     astro::stringprintf("start GP %s calibration",
                                         guider->name().c_str()));
        return guider->startCalibration(astro::guiding::GP, tracker);
    case ControlAdaptiveOptics:
        astro::event(EVENT_CLASS, astro::events::Event::GUIDE,
                     astro::stringprintf("start AO %s calibration",
                                         guider->name().c_str()));
        return guider->startCalibration(astro::guiding::AO, tracker);
    }
    debug(LOG_ERR, DEBUG_LOG, 0,
          "control type is invalid (should not happen)");
    throw BadState("not a valid control type");
}
void	GuiderStateMachine::stopGuiding() {
	if (!canStopGuiding()) {
		debug(LOG_ERR, DEBUG_LOG, 0, "cannot stop guiding in state %s",
			statename());
		throw BadState("cannot stop guiding in this state");
	}
	_state = Guide::calibrated;
}
void	GuiderStateMachine::failCalibration() {
	if (!canFailCalibration()) {
		debug(LOG_ERR, DEBUG_LOG, 0, "cannot fail calibration in state %s",
			statename());
		throw BadState("cannot fail calibration in this state");
	}
	_state = Guide::idle;
}
void	GuiderStateMachine::addCalibration() {
	if (!canAcceptCalibration()) {
		debug(LOG_ERR, DEBUG_LOG, 0,
			"cannot accept calibration in state %s", statename());
		throw BadState("cannot accept calibration in this state");
	}
	_state = Guide::calibrated;
}
void	GuiderStateMachine::configure() {
	if (!canConfigure()) {
		debug(LOG_ERR, DEBUG_LOG, 0, "cannot configured in state %s",
			statename());
		throw BadState("cannot start calibration");
	}
	_state = Guide::idle;
}
/**
 * \brief Get a servant for the Guiderport
 */
GuiderPort_ptr	Guider_impl::getGuiderPort() {
	astro::camera::GuiderPortPtr	guiderport = _guider->guiderport();
	if (!guiderport) {
		throw BadState("no guiderport defined");
	}
	ServantBuilder<GuiderPort, GuiderPort_impl>	servant;
	return servant(guiderport);
}
/**
 * \brief Get a servant for the camera
 */
Camera_ptr	Guider_impl::getCamera() {
	astro::camera::CameraPtr	camera = _guider->camera();
	if (!camera) {
		throw BadState("no camera defined");
	}
	ServantBuilder<Camera, Camera_impl>	servant;
	return servant(camera);
}
/**
 * \brief Get a servant for the CCD
 */
Ccd_ptr	Guider_impl::getCcd() {
	astro::camera::CcdPtr	ccd = _guider->ccd();
	if (!ccd) {
		throw BadState("no ccd defined");
	}
	ServantBuilder<Ccd, Ccd_impl>	servant;
	return servant(ccd);
}
Exemplo n.º 12
0
	void setPhase(const phase_type& s) {
	  current_state = s;
	  if(s < CLIFF::start || s > CLIFF::goal) {
	    std::ostringstream ostr;

	    ostr << "Simulator::setPhase(" << s << ")";
	    throw BadState(ostr.str());
	  }
	}
void	GuiderStateMachine::startCalibrating() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "start calibrating");
	if (!canStartCalibrating()) {
		debug(LOG_ERR, DEBUG_LOG, 0,
			"cannot start calibrating in state %s", statename());
		throw BadState("cannot start calibration");
	}
	_state = Guide::calibrating;
}
Exemplo n.º 14
0
void AuthenticatedSymmetricCipherBase::Resynchronize(const byte *iv, int length)
{
	if (m_state < State_KeySet)
		throw BadState(AlgorithmName(), "Resynchronize", "key is set");

	m_bufferedDataLength = 0;
	m_totalHeaderLength = m_totalMessageLength = m_totalFooterLength = 0;
	m_state = State_KeySet;

	Resync(iv, this->ThrowIfInvalidIVLength(length));
	m_state = State_IVSet;
}
Exemplo n.º 15
0
/**
 * \brief Retrieve the calibration of a device
 *
 * This method retrieves the configuration of a device. If the device is
 * unconfigured, it throws the BadState exception.
 */
Calibration GuiderI::getCalibration(ControlType calibrationtype,
                                    const Ice::Current& /* current */) {
    Calibration	calibration;
    switch (calibrationtype) {
    case ControlGuidePort:
    {
        if (!guider->hasGuideport()) {
            throw BadState("no guider port present");
        }
        if (!guider->guidePortDevice->iscalibrated()) {
            throw BadState("GP not calibrated");
        }
        //debug(LOG_DEBUG, DEBUG_LOG, 0, "device has cal id %d",
        //	guider->guidePortDevice->calibrationid());
        astro::guiding::CalibrationPtr	cal
            = guider->guidePortDevice->calibration();
        calibration = convert(cal);
        calibration.flipped = guider->guidePortDevice->flipped();
        return calibration;
    }
    case ControlAdaptiveOptics:
        if (!guider->hasAdaptiveoptics()) {
            throw BadState("no adaptive optics present");
        }
        if (!guider->adaptiveOpticsDevice->iscalibrated()) {
            throw BadState("GP not calibrated");
        }
        //debug(LOG_DEBUG, DEBUG_LOG, 0, "device has cal id %d",
        //	guider->adaptiveOpticsDevice->calibrationid());
        astro::guiding::CalibrationPtr	cal
            = guider->adaptiveOpticsDevice->calibration();
        calibration = convert(cal);
        calibration.flipped = guider->adaptiveOpticsDevice->flipped();
        return calibration;
    }
    debug(LOG_ERR, DEBUG_LOG, 0,
          "control type is invalid (should not happen)");
    throw BadState("not a valid control type");
}
Exemplo n.º 16
0
/**
 * \brief build a tracker
 */
astro::guiding::TrackerPtr	 GuiderI::getTracker() {
    // first we must make sure the data we have is consistent
    astro::camera::Exposure	exposure = guider->exposure();
    if ((exposure.frame().size().width() <= 0) ||
            (exposure.frame().size().height() <= 0)) {
        // get the frame from the ccd
        debug(LOG_DEBUG, DEBUG_LOG, 0, "using ccd frame");
        exposure.frame(guider->imager().ccd()->getInfo().getFrame());
        guider->exposure(exposure);
    }
    if ((_point.x < 0) || (_point.y < 0)) {
        astro::image::ImagePoint	c = exposure.frame().center();
        _point.x = c.x();
        _point.y = c.y();
        debug(LOG_DEBUG, DEBUG_LOG, 0, "using ccd center (%.1f,%.1f) as star",
              _point.x, _point.y);
    }
    debug(LOG_DEBUG, DEBUG_LOG, 0, "current point is (%.1f, %.1f)",
          _point.x, _point.y);

    switch (_method) {
    case TrackerUNDEFINED:
    case TrackerNULL:
        debug(LOG_DEBUG, DEBUG_LOG, 0, "construct a NULL tracker");
        return guider->getNullTracker();
        break;
    case TrackerSTAR:
        debug(LOG_DEBUG, DEBUG_LOG, 0, "construct a star tracker");
        return guider->getTracker(convert(_point));
        break;
    case TrackerPHASE:
        debug(LOG_DEBUG, DEBUG_LOG, 0, "construct a phase tracker");
        return guider->getPhaseTracker();
        break;
    case TrackerDIFFPHASE:
        debug(LOG_DEBUG, DEBUG_LOG, 0, "construct a diff tracker");
        return guider->getDiffPhaseTracker();
        break;
    case TrackerLAPLACE:
        debug(LOG_DEBUG, DEBUG_LOG, 0, "construct a laplace tracker");
        return guider->getLaplaceTracker();
        break;
    case TrackerLARGE:
        debug(LOG_DEBUG, DEBUG_LOG, 0, "construct a large tracker");
        return guider->getLargeTracker();
        break;
    }
    debug(LOG_ERR, DEBUG_LOG, 0, "tracking method is invalid "
          "(should not happen)");
    throw BadState("tracking method");
}
/**
 * \brief Retrieve the Tracking history of a guide run
 *
 * \param guiderunid	The id of the guide run for which we request
 *			the history. The value -1 means that we want
 *			to retrieve the currently running guide run
 */
Astro::TrackingHistory	*Guider_impl::getTrackingHistory(::CORBA::Long guiderunid) {
	if (guiderunid < 0) {
		// verify that we really are guiding right now
		if (astro::guiding::Guide::guiding != _guider->state()) {
			throw BadState("not currently guiding");
		}
		guiderunid = guidingrunid;
	}
	debug(LOG_DEBUG, DEBUG_LOG, 0, "get tracking history for run %d",
		guiderunid);

	// get the result from the guider factory
	return ServerDatabase().getTrackingHistory(guiderunid);
}
Exemplo n.º 18
0
void TaskQueueI::stop(const Ice::Current& /* current */) {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "stop request");
	try {
		taskqueue.stop();
		astro::event(EVENT_CLASS, astro::events::Event::TASK,
			"task queue stopped");
	} catch (const std::exception& x) {
		std::string	 cause = astro::stringprintf(
			"cannot stop: %s %s",
			astro::demangle(typeid(x).name()).c_str(), x.what());
		debug(LOG_ERR, DEBUG_LOG, 0, "%s", cause.c_str());
		throw BadState(cause);
	}
}
Exemplo n.º 19
0
TrackingHistory GuiderI::getTrackingHistoryType(Ice::Int id,
        ControlType type, const Ice::Current& /* current */) {
    debug(LOG_DEBUG, DEBUG_LOG, 0, "get tracking history %d", id);
    astro::guiding::TrackingStore	store(database);
    switch (type) {
    case ControlGuidePort:
        return convert(store.get(id,
                                 astro::guiding::GP));
    case ControlAdaptiveOptics:
        return convert(store.get(id,
                                 astro::guiding::AO));
    }
    debug(LOG_ERR, DEBUG_LOG, 0,
          "control type is invalid (should not happen)");
    throw BadState("not a valid control type");
}
Exemplo n.º 20
0
/**
 * \brief Use a calibration
 *
 * This method directs the guider to use a specific calibration from the
 * database. The flipped argument allows to use the calibration if it was
 * computed on the other side of the meridian.
 */
void GuiderI::useCalibration(Ice::Int calid, bool /* flipped */,
                             const Ice::Current& /* current */) {
    if (calid <= 0) {
        throw BadParameter("not a valid calibration id");
    }
    // retrieve guider data from the database
    try {
        guider->useCalibration(calid);
        astro::event(EVENT_CLASS, astro::events::Event::GUIDE,
                     astro::stringprintf("%s now uses calibration %d",
                                         guider->name().c_str(), calid));
    } catch (const astro::guiding::BadState x) {
        throw BadState(x.what());
    } catch (const astro::guiding::NotFound x) {
        throw NotFound(x.what());
    }
}
Exemplo n.º 21
0
TrackingPoint GuiderI::mostRecentTrackingPoint(const Ice::Current& /* current */) {
    if (astro::guiding::Guide::guiding != guider->state()) {
        throw BadState("not currently guiding");
    }

    // get info from the guider
    double	lastaction;
    astro::Point	offset;
    astro::Point	activation;
    guider->lastAction(lastaction, offset, activation);

    // construct a tracking point
    TrackingPoint	result;
    result.timeago = converttime(lastaction);
    result.trackingoffset = convert(offset);
    result.activation = convert(activation);
    return result;
}
Exemplo n.º 22
0
void AuthenticatedSymmetricCipherBase::TruncatedFinal(byte *mac, size_t macSize)
{
	if (m_totalHeaderLength > MaxHeaderLength())
		throw InvalidArgument(AlgorithmName() + ": header length of " + IntToString(m_totalHeaderLength) + " exceeds the maximum of " + IntToString(MaxHeaderLength()));

	if (m_totalFooterLength > MaxFooterLength())
	{
		if (MaxFooterLength() == 0)
			throw InvalidArgument(AlgorithmName() + ": additional authenticated data (AAD) cannot be input after data to be encrypted or decrypted");
		else
			throw InvalidArgument(AlgorithmName() + ": footer length of " + IntToString(m_totalFooterLength) + " exceeds the maximum of " + IntToString(MaxFooterLength()));
	}

	switch (m_state)
	{
	case State_Start:
	case State_KeySet:
		throw BadState(AlgorithmName(), "TruncatedFinal", "setting key and IV");

	case State_IVSet:
		AuthenticateLastHeaderBlock();
		m_bufferedDataLength = 0;
		// fall through

	case State_AuthUntransformed:
	case State_AuthTransformed:
		AuthenticateLastConfidentialBlock();
		m_bufferedDataLength = 0;
		// fall through

	case State_AuthFooter:
		AuthenticateLastFooterBlock(mac, macSize);
		m_bufferedDataLength = 0;
		break;

	default:
		CRYPTOPP_ASSERT(false);
	}

	m_state = State_KeySet;
}
Exemplo n.º 23
0
void CCM_Base::UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword /*footerLength*/)
{
	if (m_state != State_IVSet)
		throw BadState(AlgorithmName(), "SpecifyDataLengths", "or after State_IVSet");

	m_aadLength = headerLength;
	m_messageLength = messageLength;

	byte *cbcBuffer = CBC_Buffer();
	const BlockCipher &cipher = GetBlockCipher();

	cbcBuffer[0] = byte(64*(headerLength>0) + 8*((m_digestSize-2)/2) + (m_L-1));	// flag
	PutWord<word64>(true, BIG_ENDIAN_ORDER, cbcBuffer+REQUIRED_BLOCKSIZE-8, m_messageLength);
	memcpy(cbcBuffer+1, m_buffer+1, REQUIRED_BLOCKSIZE-1-m_L);
	cipher.ProcessBlock(cbcBuffer);

	if (headerLength>0)
	{
		CRYPTOPP_ASSERT(m_bufferedDataLength == 0);

		if (headerLength < ((1<<16) - (1<<8)))
		{
			PutWord<word16>(true, BIG_ENDIAN_ORDER, m_buffer, (word16)headerLength);
			m_bufferedDataLength = 2;
		}
		else if (headerLength < (W64LIT(1)<<32))
		{
			m_buffer[0] = 0xff;
			m_buffer[1] = 0xfe;
			PutWord<word32>(false, BIG_ENDIAN_ORDER, m_buffer+2, (word32)headerLength);
			m_bufferedDataLength = 6;
		}
		else
		{
			m_buffer[0] = 0xff;
			m_buffer[1] = 0xff;
			PutWord<word64>(false, BIG_ENDIAN_ORDER, m_buffer+2, headerLength);
			m_bufferedDataLength = 10;
		}
	}
}
Exemplo n.º 24
0
/**
 * \brief Uncalibrate a device
 *
 * Since all configured devices are used for guiding, there must be a method
 * to uncalibrate a device so that it is no longer used for guiding.
 */
void	GuiderI::unCalibrate(ControlType calibrationtype,
                             const Ice::Current& /* current */) {
    // retrieve guider data from the database
    try {
        switch (calibrationtype) {
        case ControlGuidePort:
            astro::event(EVENT_CLASS, astro::events::Event::GUIDE,
                         astro::stringprintf("GP %s uncalibrated",
                                             guider->name().c_str()));
            guider->unCalibrate(astro::guiding::GP);
            break;
        case ControlAdaptiveOptics:
            astro::event(EVENT_CLASS, astro::events::Event::GUIDE,
                         astro::stringprintf("AO %s uncalibrated",
                                             guider->name().c_str()));
            guider->unCalibrate(astro::guiding::AO);
            break;
        }
    } catch (const astro::guiding::BadState& exception) {
        throw BadState(exception.what());
    }
}
/**
 * \brief Retrieve the most recent point found by the tracker
 */
Astro::TrackingPoint	Guider_impl::mostRecentTrackingPoint() {
	// verify that we really are guiding right now
	if (astro::guiding::Guide::guiding != _guider->state()) {
		throw BadState("not currently guiding");
	}

	// ok, we are guiding. Prepare a result structure
	Astro::TrackingPoint	result;
	// So we query the guider for the contents of this structure
	double	lastaction;
	astro::Point	offset;
	astro::Point	activation;
	_guider->lastAction(lastaction, offset, activation);
	result.timeago = astro::Timer::gettime() - lastaction;
	result.trackingoffset.x = offset.x();
	result.trackingoffset.y = offset.y();
	result.activation.x = activation.x();
	result.activation.y = activation.y();

	// that's it, we are read, return the structure
	return result;
}
Exemplo n.º 26
0
/**
 * \brief startExposure
 *
 * This method starts the thread that is
 */
void	ThreadCcd::startExposure(const Exposure& exposure) {
	std::unique_lock<std::recursive_mutex>	lock(_mutex);
	// make sure we are in the right state
	if (exposureStatus() != CcdState::idle) {
		std::string	msg("not idle: start exposure in idle state");
		debug(LOG_ERR, DEBUG_LOG, 0, "%s", msg.c_str());
		throw BadState(msg);
	}

	// find out whether there is a joinable thread
	if (_thread.joinable()) {
		_thread.join();
	}

	// prepare the exposure structure
	this->exposure = exposure;

	// start a thread
	state(CcdState::exposing);
	_running = true;
	_thread = std::thread(treadccdmain, this);
}
Exemplo n.º 27
0
Arquivo: VP.c Projeto: berkus/nemesis
static void FreeChannel_m(VP_cl *self, Channel_Endpoint ep )
{
    dcb_rw_t     *rwp = RW(self);
    dcb_ro_t     *rop = RO(self);
    ep_rw_t      *eprw;
    ep_ro_t      *epro;

    if ( ep >= rop->num_eps ) {
	DB(eprintf("VP$FreeChannel: invalid EP.\n"));
	RAISE_Channel$Invalid( ep );
    }

    epro = DCB_EPRO(rop,ep);
    eprw = DCB_EPRW(rop,ep);
    if ( epro->peer_dcb != NULL || eprw->state == Channel_State_Free ) {
	DB(eprintf("VP$FreeChannel: Bad State.\n"));
	RAISE_Channel$BadState( ep, eprw->state );
    }
    
    eprw->state = Channel_State_Free;
    eprw->ack   = (word_t)(rwp->free_eps);
    rwp->free_eps = eprw;
}
Exemplo n.º 28
0
	static void drawingPosition(int& w, int& h, phase_type p) {
	  switch(p) {
	  case start:
	    w = 0;
	    h = WIDTH;
	    break;
	  case goal:
	    w = LENGTH-1;
	    h = WIDTH;
	    break;
	  default:
	    if(p<0 || p >= LENGTH*WIDTH+2) {
	      std::ostringstream os;
	      os << "Cliff<" << LENGTH << ',' << WIDTH << ">::drawingPosition(w,h," 
		 << p << ") : Out of bounds.";
	      throw BadState(os.str());
	    }

	    p--;
	    w = p%LENGTH;
	    h = WIDTH-1-p/LENGTH;
	    break;
	  }
	}