keep object inside circle

i have a texture attached to the Input.mousePosition. so when i move mouse around texture follows the mouse. i want to limit the area of movement to the circle. so mouse can go outside the circle but the texture should stick to the border of the circle. here is a image that could help. i guess it is a simple math, but i just cant figure out how to control what is used and what not

any directions should be appreciated: alt text

Pseudocode (untested):

Vector2 diff = mousePosition - center;
float distance = diff.magnitude;
if (distance > circleRadius) {
    cursorPosition = center + (diff / distance) * circleRadius;
} else {
    cursorPosition = mousePosition;